Documentation ¶
Overview ¶
Package oauth2 provides handlers for OAuth2 login and callback requests.
Index ¶
- Variables
- func CallbackHandler(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 StateFromContext(ctx context.Context) (string, error)
- func StateHandler(config sessions.CookieConfig, success http.Handler) http.Handler
- func TokenFromContext(ctx context.Context) (*oauth2.Token, error)
- func WithError(ctx context.Context, err error) context.Context
- func WithState(ctx context.Context, state string) context.Context
- func WithToken(ctx context.Context, token *oauth2.Token) context.Context
Constants ¶
This section is empty.
Variables ¶
var ( // ErrContextMissingToken is returned when the context is missing the token value ErrContextMissingToken = errors.New("oauth2: context missing token") // ErrContextMissingStateValue is returned when the context is missing the state value ErrContextMissingStateValue = errors.New("oauth2: context missing state value") // ErrInvalidState is returned when the state parameter is invalid ErrInvalidState = errors.New("oauth2: invalid oauth2 state parameter") // ErrFailedToGenerateToken is returned when a token cannot be generated ErrFailedToGenerateToken = errors.New("failed to generate token") // ErrMissingCodeOrState is returned when the request is missing the code or state query string parameter ErrMissingCodeOrState = errors.New("oauth2: request missing code or state") // 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 parses the auth code + state and compares it to the state value from the context
func ErrorFromContext ¶
ErrorFromContext returns the error value from the ctx or an error that the context was missing an error value
func LoginHandler ¶
LoginHandler reads the state value from the context and redirects requests to the AuthURL with that state value
func StateFromContext ¶
StateFromContext returns the state value from the ctx
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 TokenFromContext ¶
TokenFromContext returns the Token from the ctx
Types ¶
This section is empty.