cache

package
v0.0.0-...-4e75552 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2020 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// AuthCodeFlowID is prepended to a refresh token issued by the Authorization Code flow
	AuthCodeFlowID = "AUTHCODE"
)
View Source
const (

	// ClientCredsFlowID is prepended to access and refresh tokens issued by the Client Credentials flow
	ClientCredsFlowID = "CLICREDS"
)
View Source
const (

	// ImplicitFlowID is prepended to access tokens issued by the Implicit Grant flow
	ImplicitFlowID = "IMPLICIT"
)
View Source
const (

	// ROPCFlowID is prepended to access and refresh tokens issued by the ROPC flow
	ROPCFlowID = "PASSCRED"
)

Variables

This section is empty.

Functions

func AuthCodeRefreshTokenExists

func AuthCodeRefreshTokenExists(refreshToken string, invalidateIfFound bool) bool

AuthCodeRefreshTokenExists checks if the refresh token exists in the Redis cache and returns the appropriate boolean value. Params: refreshToken: the token to look for in the cache invalidateIfFound: if true, the token is invalidated if found

func CloseConn

func CloseConn(conn redis.Conn)

CloseConn closes a Redis connection. Also captures the error, if any, and logs it.

func ClosePool

func ClosePool()

ClosePool closes the pool of Redis connections. Also captures the error, if any, and logs it.

func NewAuthCodeGrant

func NewAuthCodeGrant(redirectURI string) string

NewAuthCodeGrant generates a new authorization grant and adds it to a Redis cache set. This function takes the redirect URI as an argument, since RFC 6749 requires the same URI to be used in the token request as was used in the authorization grant request, if any. Thus, we store it along with the authorization grant in order for us to verify it against the one sent in the token request. Refer: https://tools.ietf.org/html/rfc6749#section-4.1.3

func NewConn

func NewConn() redis.Conn

NewConn returns a Redis connection. It is the responsibility of the receiver to close the connection.

func ROPCRefreshTokenExists

func ROPCRefreshTokenExists(refreshToken string, invalidateIfFound bool) bool

ROPCRefreshTokenExists checks if the refresh token exists in the Redis cache and returns the appropriate boolean value. Params: refreshToken: the token to look for in the cache invalidateIfFound: if true, the token is invalidated if found

func VerifyAuthCodeToken

func VerifyAuthCodeToken(token string) bool

VerifyAuthCodeToken checks if the token exists in the Redis cache. Returns true if token found, false otherwise.

func VerifyClientCredsToken

func VerifyClientCredsToken(token string) bool

VerifyClientCredsToken checks if the token exists in the Redis cache. Returns true if token found, false otherwise.

func VerifyImplicitToken

func VerifyImplicitToken(token string) bool

VerifyImplicitToken checks if the token exists in the Redis cache. Returns true if token found, false otherwise.

func VerifyROPCToken

func VerifyROPCToken(token string) bool

VerifyROPCToken checks if the token exists in the Redis cache. Returns true if token found, false otherwise.

Types

type AuthCodeToken

type AuthCodeToken struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	ExpiresIn    int    `json:"expires_in"`
}

AuthCodeToken represents a token issued by the Authorization Code flow https://tools.ietf.org/html/rfc6749#section-4.1.3

func NewAuthCodeRefreshToken

func NewAuthCodeRefreshToken(refreshToken string) (*AuthCodeToken, error)

NewAuthCodeRefreshToken returns new token for the previously issued refresh token The refresh token is kept intact and can be used for future requests.

func NewAuthCodeToken

func NewAuthCodeToken(code, refreshToken, redirectURI string) (*AuthCodeToken, error)

NewAuthCodeToken issues new access tokens for the Authorization Code flow. It searches for 'code' in the Redis cache and throws errors if not found. If found, it checks if it has crossed is expiry limit which is 10 minutes. If crossed, an error is thrown. Else a new token is generated and returned. Refer RFC 6749 Section 4.1.2 (https://tools.ietf.org/html/rfc6749#section-4.1.2)

type ClientCredentialsToken

type ClientCredentialsToken struct {
	AccessToken string `json:"access_token"`
	ExpiresIn   int    `json:"expires_in"`
}

ClientCredentialsToken represents a token issued by the Resource Owner Password Credentials flow https://tools.ietf.org/html/rfc6749#section-4.3.3

func NewClientCredsToken

func NewClientCredsToken() (*ClientCredentialsToken, error)

NewClientCredsToken issues new access tokens for the Client Credentials flow. It generates and stores a token and stores it along with its meta data in the Redis cache.

type ImplicitToken

type ImplicitToken struct {
	AccessToken string `json:"access_token"`
	ExpiresIn   int    `json:"expires_in"`
}

ImplicitToken represents a token issued by the Implicit Grant flow https://tools.ietf.org/html/rfc6749#section-4.2.2

func NewImplicitToken

func NewImplicitToken() (*ImplicitToken, error)

NewImplicitToken issues new access tokens for the Implicit Grant flow. It generates and stores a token and stores it along with its meta data in the Redis cache.

type ROPCToken

type ROPCToken struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	ExpiresIn    int    `json:"expires_in"`
}

ROPCToken represents a token issued by the Resource Owner Password Credentials flow https://tools.ietf.org/html/rfc6749#section-4.3.3

func NewROPCRefreshToken

func NewROPCRefreshToken(refreshToken string) (*ROPCToken, error)

NewROPCRefreshToken returns new token for the previously issued refresh token The refresh token is kept intact and can be used for future requests.

func NewROPCToken

func NewROPCToken(refreshToken string) (*ROPCToken, error)

NewROPCToken issues new access and refresh tokens for the ROPC flow. It generates and stores a token and stores it along with its meta data in the Redis cache.

Jump to

Keyboard shortcuts

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