gologin: github.com/dghubble/gologin/oauth2 Index | Files

package oauth2

import "github.com/dghubble/gologin/oauth2"

Package oauth2 provides handlers for OAuth2 login and callback requests.


Package Files

context.go doc.go login.go


var (
    ErrInvalidState = errors.New("oauth2: Invalid OAuth2 state parameter")

Errors which may occur on login.

func CallbackHandler Uses

func CallbackHandler(config *oauth2.Config, success, failure http.Handler) http.Handler

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.

func LoginHandler Uses

func LoginHandler(config *oauth2.Config, failure http.Handler) http.Handler

LoginHandler handles OAuth2 login requests by reading the state value from the ctx and redirecting requests to the AuthURL with that state value.

func StateFromContext Uses

func StateFromContext(ctx context.Context) (string, error)

StateFromContext returns the state value from the ctx.

func StateHandler Uses

func StateHandler(config gologin.CookieConfig, success http.Handler) http.Handler

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.

func TokenFromContext Uses

func TokenFromContext(ctx context.Context) (*oauth2.Token, error)

TokenFromContext returns the Token from the ctx.

func WithState Uses

func WithState(ctx context.Context, state string) context.Context

WithState returns a copy of ctx that stores the state value.

func WithToken Uses

func WithToken(ctx context.Context, token *oauth2.Token) context.Context

WithToken returns a copy of ctx that stores the Token.

Package oauth2 imports 9 packages (graph) and is imported by 13 packages. Updated 2017-01-11. Refresh now. Tools for package owners.