token

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2020 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ClientIDCookie is the cookie name used to set the token's
	// ClientID value on a client.
	ClientIDCookie = "CLIENTID"
	// RefreshTokenCookie is the cookie name used to set the refresh
	// token value on a client.
	RefreshTokenCookie = "REFRESHTOKEN"
)

Variables

This section is empty.

Functions

func NewService

func NewService(options ...ConfigOption) auth.TokenService

NewService returns a new TokenService.

func WithOTPAddress added in v0.2.0

func WithOTPAddress(address string) auth.TokenOption

WithOTPAddress sets an address to receive a randomly generated OTP code. If a delivery method is configured on the token without a corresponding address, we will deliver the OTP code to the user's default sending address.

func WithOTPDeliveryMethod added in v0.2.0

func WithOTPDeliveryMethod(method auth.DeliveryMethod) auth.TokenOption

WithOTPDeliveryMethod sets a delivery method (e.g. email, phone) to be used as a channel for sending OTP codes related to a JWT token.

func WithRefreshableToken added in v0.2.0

func WithRefreshableToken(token *auth.Token) auth.TokenOption

WithRefreshableToken uses an older JWT token as a basis for creating a new token. ClientID hashes and the token ID will be carried over to the new token with an updated expiry time.

Types

type ConfigOption

type ConfigOption func(*service)

ConfigOption configures the service.

func WithCookieDomain

func WithCookieDomain(domain string) ConfigOption

WithCookieDomain configures the service with the domain for a secure cookie.

func WithCookieMaxAge

func WithCookieMaxAge(age int) ConfigOption

WithCookieMaxAge sets the max age for an HTTP cookie. Defaults to 7 days.

func WithDB

func WithDB(db rediser) ConfigOption

WithDB configures the service with a redis DB

func WithIssuer

func WithIssuer(issuer string) ConfigOption

WithIssuer is the issuer identity for the JWT token.

func WithLogger

func WithLogger(l log.Logger) ConfigOption

WithLogger configures the service with a logger.

func WithOTP

func WithOTP(o auth.OTPService) ConfigOption

WithOTP configures the service with an OTP management service.

func WithRefreshTokenExpiry added in v0.2.0

func WithRefreshTokenExpiry(expiresIn time.Duration) ConfigOption

WithRefreshTokenExpiry defines how long a refresh token is valid for. The default value is 15 days.

func WithRepoManager added in v0.2.0

func WithRepoManager(repoMngr auth.RepositoryManager) ConfigOption

WithRepoManager configures the service with a new RepositoryManager.

func WithSecret

func WithSecret(secret string) ConfigOption

WithSecret configures the service with a secret value for signing functions.

func WithTokenExpiry

func WithTokenExpiry(expiresIn time.Duration) ConfigOption

WithTokenExpiry defines how long tokens are valid for. The default value is 20 minutes.

type RefreshToken added in v0.2.0

type RefreshToken struct {
	Code      string `json:"code"`
	ExpiresAt int64  `json:"expires_at"`
}

RefreshToken is a token capable of refreshing an expired JWT token.

type Response

type Response struct {
	Token        string `json:"token"`
	ClientID     string `json:"clientID,omitempty"`
	RefreshToken string `json:"refreshToken,omitempty"`
}

Response ensures consistent formatting for JSON APIs.

Jump to

Keyboard shortcuts

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