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

package github

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

Package github provides Github OAuth2 login and callback handlers.

Index

Package Files

context.go doc.go login.go

Variables

var (
    ErrUnableToGetGithubUser = errors.New("github: unable to get Github User")
)

Github login errors

func CallbackHandler Uses

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

CallbackHandler handles Github redirection URI requests and adds the Github access token and User to the ctx. If authentication succeeds, handling delegates to the success handler, otherwise to the failure handler.

func EnterpriseCallbackHandler Uses

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

EnterpriseCallbackHandler handles Github Enterprise redirection URI requests and adds the Github access token and User to the ctx. If authentication succeeds,handling delegates to the success handler, otherwise to the failure handler. The Github Enterprise API URL is inferred from the OAuth2 config's AuthURL endpoint.

func LoginHandler Uses

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

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 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 UserFromContext Uses

func UserFromContext(ctx context.Context) (*github.User, error)

UserFromContext returns the Github User from the ctx.

func WithUser Uses

func WithUser(ctx context.Context, user *github.User) context.Context

WithUser returns a copy of ctx that stores the Github User.

Package github imports 9 packages (graph) and is imported by 3 packages. Updated 2018-12-21. Refresh now. Tools for package owners.