github

package
v0.2.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 5, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package github provides GitHub OAuth2 login and callback handlers.

Index

Constants

This section is empty.

Variables

View Source
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")
)
View Source
var DefaultFailureHandler = http.HandlerFunc(failureHandler)

DefaultFailureHandler responds with a 400 status code and message parsed from the context

Functions

func CallbackHandler

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

CallbackHandler adds the GitHub access token and User to the ctx

func EnterpriseCallbackHandler

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

func ErrorFromContext

func ErrorFromContext(ctx context.Context) error

ErrorFromContext returns the error value from the ctx or an error that the context was missing an error value

func LoginHandler

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

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

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

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

UserFromContext returns the GitHub User from the context

func WithError

func WithError(ctx context.Context, err error) context.Context

WithError returns a copy of context that stores the given error value

func WithUser

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

WithUser returns a copy of context that stores the GitHub User

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL