githuboauth

package
v0.0.0-...-6ca4c02 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 19, 2018 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GithubClientGetter

type GithubClientGetter interface {
	GetGithubClient(accessToken string, dryRun bool) GithubClientWrapper
}

GithubClientGetter interface is used by handleRedirect to get github client.

func NewGithubClientGetter

func NewGithubClientGetter() GithubClientGetter

type GithubClientWrapper

type GithubClientWrapper interface {
	GetUser(login string) (*github.User, error)
}

GithubClientWrapper is an interface for github clients which implements GetUser method that returns github.User.

type GithubOAuthAgent

type GithubOAuthAgent struct {
	// contains filtered or unexported fields
}

GithubOAuth Agent represents an agent that takes care Github authentication process such as handles login request from users or handles redirection from Github OAuth server.

func NewGithubOAuthAgent

func NewGithubOAuthAgent(config *config.GithubOAuthConfig, logger *logrus.Entry) *GithubOAuthAgent

Returns new GithubOAUth Agent.

func (*GithubOAuthAgent) HandleLogin

func (ga *GithubOAuthAgent) HandleLogin(client OAuthClient) http.HandlerFunc

HandleLogin handles Github login request from front-end. It starts a new git oauth session and redirect user to Github OAuth end-point for authentication.

func (*GithubOAuthAgent) HandleLogout

func (ga *GithubOAuthAgent) HandleLogout(client OAuthClient) http.HandlerFunc

HandleLogout handles Github logout request from front-end. It invalidates cookie sessions and redirect back to the front page.

func (*GithubOAuthAgent) HandleRedirect

func (ga *GithubOAuthAgent) HandleRedirect(client OAuthClient, getter GithubClientGetter) http.HandlerFunc

HandleRedirect handles the redirection from Github. It exchanges the code from redirect URL for user access token. The access token is then saved to the cookie and the page is redirected to the final destination in the config, which should be the front-end.

type OAuthClient

type OAuthClient interface {
	// Exchanges code from github oauth redirect for user access token.
	Exchange(ctx context.Context, code string) (*oauth2.Token, error)
	// Returns a URL to OAuth 2.0 github's consent page. The state is a token to protect user from
	// XSRF attack.
	AuthCodeURL(state string, opts ...oauth2.AuthCodeOption) string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL