githuboauth

package
v0.0.0-...-97238d6 Latest Latest
Warning

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

Go to latest
Published: May 29, 2019 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 Agent

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

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 NewAgent

func NewAgent(config *config.GithubOAuthConfig, logger *logrus.Entry) *Agent

NewAgent returns a new Github OAuth Agent.

func (*Agent) HandleLogin

func (ga *Agent) 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 (*Agent) HandleLogout

func (ga *Agent) 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 (*Agent) HandleRedirect

func (ga *Agent) 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 GithubClientGetter

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

GithubClientGetter interface is used by handleRedirect to get a Github client.

func NewGithubClientGetter

func NewGithubClientGetter() GithubClientGetter

NewGithubClientGetter returns a new instance of GithubClientGetter. It uses the githubClientGetter implementation.

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 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 Github's OAuth 2.0 consent page. The state is a token to protect the user
	// from an XSRF attack.
	AuthCodeURL(state string, opts ...oauth2.AuthCodeOption) string
}

OAuthClient is an interface for a Github OAuth client.

Jump to

Keyboard shortcuts

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