Back to

Package security

Latest Go to latest

The latest major version is .

Published: 4 days ago | License: MIT | Module:


func ContextWithToken

func ContextWithToken(targetCtx context.Context, token Token) context.Context

ContextWithToken creates a new Context with the token

func GetAuthHeader

func GetAuthHeader(tok Token) string

GetAuthHeader creates the valid value for the authentication header

func GetBearerTokenFromHeader

func GetBearerTokenFromHeader(authHeader string) string

GetBearerTokenFromHeader removes the prefix of authHeader authHeader should be the value of the authorization header field. success: returns the bearer token without the prefix error: return an empty token

type Authorizer

type Authorizer interface {
	// Authorize should authorize a request.
	// Success: returns a context with information of the authorization
	// Error: Handles Errors (logging and creating a response with the error),
	// 		  returns the unchanged context of the request and false
	Authorize(r *http.Request, w http.ResponseWriter) (context.Context, bool)

Authorizer describes the needed functions for authorization, already implemented in oauth2.Authorizer and apikey.Authorizer

type CanAuthorize

type CanAuthorize interface {
	// CanAuthorizeRequest should check if a request contains the needed information to be authorized
	CanAuthorizeRequest(r http.Request) bool

CanAuthorize offers a method to check if an authorizer can authorize a request

type Token

type Token interface {
	// GetValue returns the bearer token
	GetValue() string

Token represents an authentication token.

func GetTokenFromContext

func GetTokenFromContext(ctx context.Context) (Token, bool)

GetTokenFromContext returns the token, if it is stored in the context, and true if the token is present.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier