Package oauth2 provides handlers for OAuth2 login and callback requests.
Errors which may occur on login.
CallbackHandler handles OAuth2 redirection URI requests by parsing the auth code and state, comparing with the state value from the ctx, and obtaining an OAuth2 Token.
LoginHandler handles OAuth2 login requests by reading the state value from the ctx and redirecting requests to the AuthURL with that state value.
StateFromContext returns the state value from the ctx.
StateHandler checks for a state cookie. If found, the state value is read and added to the ctx. Otherwise, a non-guessable value is added to the ctx and to a (short-lived) state cookie issued to the requester.
Implements OAuth 2 RFC 6749 10.12 CSRF Protection. If you wish to issue state params differently, write a http.Handler which sets the ctx state, using oauth2 WithState(ctx, state) since it is required by LoginHandler and CallbackHandler.
TokenFromContext returns the Token from the ctx.
WithState returns a copy of ctx that stores the state value.
WithToken returns a copy of ctx that stores the Token.