Documentation
¶
Overview ¶
Package github provides GitHub OAuth2 login and callback handlers.
Index ¶
- Constants
- Variables
- func CallbackHandler(config *oauth2.Config, success, failure http.Handler) http.Handler
- func EnterpriseCallbackHandler(config *oauth2.Config, success, failure http.Handler) http.Handler
- func ErrorFromContext(ctx context.Context) error
- func LoginHandler(config *oauth2.Config, failure http.Handler) http.Handler
- func StateHandler(config sessions.CookieConfig, success http.Handler) http.Handler
- func UserFromContext(ctx context.Context) (*github.User, error)
- func VerifyClientToken(ctx context.Context, token *oauth2.Token, config *oauth2.Config, email string, ...) (err error)
- func WithError(ctx context.Context, err error) context.Context
- func WithUser(ctx context.Context, user *github.User) context.Context
- type ClientConfig
- type GitHubClient
- type GitHubCreator
- type GitHubInterface
- type GitHubMock
- type ProviderConfig
- type UsersMock
Constants ¶
const (
ProviderName = "GITHUB"
)
Variables ¶
var ( // ErrServerError returns a generic server error ErrServerError = errors.New("server error") // ErrContextMissingGithubUser is returned when the GitHub user is missing from the context ErrContextMissingGithubUser = errors.New("context missing github user") // ErrFailedConstructingEndpointURL is returned when URL is invalid and unable to be parsed ErrFailedConstructingEndpointURL = errors.New("error constructing URL") // ErrCreatingGithubClient is returned when the GitHub client cannot be created ErrCreatingGithubClient = errors.New("error creating github client") // ErrUnableToGetGithubUser when the user cannot be retrieved from GitHub ErrUnableToGetGithubUser = errors.New("unable to get github user") // ErrPrimaryEmailNotFound when the user's primary email cannot be retrieved from GitHub ErrPrimaryEmailNotFound = errors.New("unable to get primary email address") // ErrContextMissingErrorValue is returned when the context does not have an error value ErrContextMissingErrorValue = fmt.Errorf("context missing error value") )
var DefaultFailureHandler = http.HandlerFunc(failureHandler)
DefaultFailureHandler responds with a 400 status code and message parsed from the context
Functions ¶
func CallbackHandler ¶
CallbackHandler adds the GitHub access token and User to the ctx
func EnterpriseCallbackHandler ¶
EnterpriseCallbackHandler handles GitHub Enterprise redirection URI requests and adds the GitHub access token and User to the ctx
func ErrorFromContext ¶
ErrorFromContext returns the error value from the ctx or an error that the context was missing an error value
func LoginHandler ¶
LoginHandler handles Github login requests by reading the state value from the ctx and redirecting requests to the AuthURL with that state value
func StateHandler ¶
StateHandler checks for a state cookie, if found, adds to context; if missing, a random generated value is added to the context and to a (short-lived) state cookie issued to the requester - this implements OAuth 2 RFC 6749 10.12 CSRF Protection
func UserFromContext ¶
UserFromContext returns the GitHub User from the context
func VerifyClientToken ¶
func VerifyClientToken(ctx context.Context, token *oauth2.Token, config *oauth2.Config, email string, clientConfig *ClientConfig) (err error)
VerifyClientToken checks the client token and returns an error if it is invalid
Types ¶
type ClientConfig ¶
ClientConfig holds the configuration for the GitHub client
type GitHubClient ¶
type GitHubClient struct {
Users githubUserService
}
GitHubClient defines all necessary methods used by the client
type GitHubCreator ¶
type GitHubCreator struct {
Config *ClientConfig
}
GitHubCreator implements GitHubInterface
func (*GitHubCreator) GetConfig ¶
func (g *GitHubCreator) GetConfig() *ClientConfig
GetConfig returns the current configuration
func (*GitHubCreator) NewClient ¶
func (g *GitHubCreator) NewClient(httpClient *http.Client) GitHubClient
NewClient returns a new GitHubClient
func (*GitHubCreator) SetConfig ¶
func (g *GitHubCreator) SetConfig(config *ClientConfig)
SetConfig sets the configuration
type GitHubInterface ¶
type GitHubInterface interface { NewClient(httpClient *http.Client) GitHubClient GetConfig() *ClientConfig SetConfig(config *ClientConfig) }
GitHubInterface defines all necessary methods https://godoc.org/github.com/google/go-github/github#NewClient
type GitHubMock ¶
type GitHubMock struct {
Config *ClientConfig
}
GitHubMock implements GitHubInterface
func (*GitHubMock) GetConfig ¶
func (g *GitHubMock) GetConfig() *ClientConfig
GetConfig returns the current configuration
func (*GitHubMock) NewClient ¶
func (g *GitHubMock) NewClient(httpClient *http.Client) GitHubClient
NewClient returns a new mock GitHubClient
func (*GitHubMock) SetConfig ¶
func (g *GitHubMock) SetConfig(config *ClientConfig)
SetConfig sets the configuration
type ProviderConfig ¶
type ProviderConfig struct { // ClientID is the public identifier for the GitHub oauth2 client ClientID string `json:"clientId" koanf:"clientId" jsonschema:"required"` // ClientSecret is the secret for the GitHub oauth2 client ClientSecret string `json:"clientSecret" koanf:"clientSecret" jsonschema:"required"` // ClientEndpoint is the endpoint for the GitHub oauth2 client ClientEndpoint string `json:"clientEndpoint" koanf:"clientEndpoint" default:"http://localhost:17608"` // Scopes are the scopes that the GitHub oauth2 client will request Scopes []string `json:"scopes" koanf:"scopes" jsonschema:"required"` // RedirectURL is the URL that the GitHub oauth2 client will redirect to after authentication with Github RedirectURL string `json:"redirectUrl" koanf:"redirectUrl" jsonschema:"required" default:"/v1/github/callback"` }
ProviderConfig represents the configuration settings for a Github Oauth Provider