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 WithError(ctx context.Context, err error) context.Context
- func WithUser(ctx context.Context, user *github.User) context.Context
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
Types ¶
This section is empty.