Documentation ¶
Overview ¶
Package oauth2 implements an http.Handler that performs the 3-leg OAuth2 authentication flow. While it can be used with all OAuth2 providers, functions are provided specifically for GitHub integration.
Index ¶
- Constants
- Variables
- func DefaultErrorCallback(w http.ResponseWriter, r *http.Request, err error)
- func DefaultLoginCallback(w http.ResponseWriter, r *http.Request, login *Login)
- func GetConfig(c githubapp.Config, scopes []string) *oauth2.Config
- func NewHandler(c *oauth2.Config, params ...Param) http.Handler
- type ErrorCallback
- type Login
- type LoginCallback
- type LoginError
- type Param
- type SessionStateStore
- type StateStore
Constants ¶
View Source
const (
DefaultRoute = "/api/github/auth"
)
Variables ¶
View Source
var (
DefaultSessionKey = "oauth2.state"
)
View Source
var (
ErrInvalidState = errors.New("oauth2: invalid state value")
)
Functions ¶
func DefaultErrorCallback ¶
func DefaultErrorCallback(w http.ResponseWriter, r *http.Request, err error)
func DefaultLoginCallback ¶
func DefaultLoginCallback(w http.ResponseWriter, r *http.Request, login *Login)
Types ¶
type ErrorCallback ¶
type ErrorCallback func(w http.ResponseWriter, r *http.Request, err error)
type LoginCallback ¶
type LoginCallback func(w http.ResponseWriter, r *http.Request, login *Login)
type LoginError ¶
type LoginError string
LoginError is an error returned as a parameter by the OAuth provider.
func (LoginError) Error ¶
func (err LoginError) Error() string
type Param ¶
type Param func(*handler)
func ForceTLS ¶
ForceTLS determines if generated URLs always use HTTPS. By default, the protocol of the request is used.
func WithStore ¶
func WithStore(ss StateStore) Param
WithStore sets the StateStore used to create and verify OAuth2 states. The default state store uses a static value, is insecure, and is not suitable for production use.
type SessionStateStore ¶
func (*SessionStateStore) GenerateState ¶
func (s *SessionStateStore) GenerateState(w http.ResponseWriter, r *http.Request) (string, error)
func (*SessionStateStore) VerifyState ¶
type StateStore ¶
type StateStore interface { // GenerateState creates a new state value, storing it in a way that can be // retrieved by VerifyState at a later point. GenerateState(w http.ResponseWriter, r *http.Request) (string, error) // VerifyState checks that the state associated with the request matches // the given state. To avoid timing attacks, implementations should use // constant-time comparisons if possible. VerifyState(r *http.Request, state string) (bool, error) }
StateStore generates and verifies the state parameter for OAuth2 flows.
Click to show internal directories.
Click to hide internal directories.