security

package
v0.1.73 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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

Types

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 added in v0.1.27

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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