Documentation ¶
Overview ¶
Package bearer provides structures and functions to implement the additional OAuth2 Bearer Token specification.
Index ¶
Constants ¶
const TokenType = "bearer"
TokenType is the bearer token type as defined by the OAuth2 Bearer Token spec.
Variables ¶
This section is empty.
Functions ¶
func NewTokenResponse ¶
func NewTokenResponse(token string, expiresIn int) *oauth2.TokenResponse
NewTokenResponse creates and returns a new token response that carries a bearer token.
func ParseToken ¶
ParseToken parses and returns the bearer token from a request. It will return an Error instance if the extraction failed.
Note: The spec also allows obtaining the bearer token from query parameters and the request body (form data). This implementation only supports obtaining the token from the "Authorization" header as this is the most common use case and considered most secure.
func WriteError ¶
func WriteError(w http.ResponseWriter, err error) error
WriteError will write the specified error to the response writer. The function will fall back and write an internal server error if the specified error is not known.
Types ¶
type Error ¶
type Error struct { Name string Description string URI string Realm string Scope string Status int }
An Error represents an unsuccessful bearer token authentication.
func InsufficientScope ¶
InsufficientScope constructs and error that indicates that the request requires higher privileges than provided by the access token.
func InvalidRequest ¶
InvalidRequest constructs and error that indicates that the request is missing a required parameter, includes an unsupported parameter or parameter value, repeats the same parameter, uses more than one method for including an access token, or is otherwise malformed.
func InvalidToken ¶
InvalidToken constructs and error that indicates that the access token provided is expired, revoked, malformed, or invalid for other reasons.
func ProtectedResource ¶
func ProtectedResource() *Error
ProtectedResource constructs and error that indicates that the requested resource needs authentication.
func ServerError ¶ added in v0.2.0
func ServerError() *Error
ServerError constructs an error that indicates that there was an internal server error.
Note: This error type is not defined by the spec, but has been added to increase the readability of the source code.