authorization

package
v0.0.0-...-6bf1803 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddUserIDHeader

func AddUserIDHeader(r *http.Request, claim *Claim)

AddUserIDHeader adds a header to the request that represents the user ID

func BlacklistToken

func BlacklistToken(token string)

BlacklistToken blacklists a token so that it cannot be used anymore

func CleanBlacklist

func CleanBlacklist(cleanInterval time.Duration)

CleanBlacklist starts a go routine that periodically clears the black list

func GenerateJWTToken

func GenerateJWTToken(username string) (string, time.Time, error)

GenerateJWTToken generates a JWT token for the provided username

func GetAuthToken

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

GetAuthToken extracts the auth token from a request

func GetUserIDFromRequest

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

GetUserIDFromRequest returns the user ID from the request

func IsBlacklisted

func IsBlacklisted(token string) bool

IsBlacklisted checks if a token is blacklisted

func RemoveUserIDHeader

func RemoveUserIDHeader(r *http.Request)

RemoveUserIDHeader removes the header that contains the user ID

func SetAuthCookie

func SetAuthCookie(w http.ResponseWriter, tokenString string, expires time.Time)

SetAuthCookie add an auth cookie to the response writer

Types

type Claim

type Claim struct {
	Username string `json:"username"`
	jwt.StandardClaims
}

Claim uses the standard JWT Claim to create a custom claim

func ValidateToken

func ValidateToken(tknStr string) (bool, *Claim, error)

ValidateToken validates whether the value of the receoved key is a valid token

Jump to

Keyboard shortcuts

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