bearer

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2020 License: MIT Imports: 5 Imported by: 1

Documentation

Overview

Package bearer provides structures and functions to implement the additional OAuth2 Bearer Token specification.

Index

Constants

View Source
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

func ParseToken(r *http.Request) (string, error)

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

func InsufficientScope(necessaryScope string) *Error

InsufficientScope constructs and error that indicates that the request requires higher privileges than provided by the access token.

func InvalidRequest

func InvalidRequest(description string) *Error

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

func InvalidToken(description string) *Error

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.

func (*Error) Error

func (e *Error) Error() string

Error implements the error interface.

func (*Error) Map

func (e *Error) Map() map[string]string

Map returns a map of all fields that can be presented to the client.

func (*Error) Params

func (e *Error) Params() string

Params returns an string encoded representation of the error parameters.

Jump to

Keyboard shortcuts

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