oauth

package
v0.0.0-...-cc150fd Latest Latest
Warning

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

Go to latest
Published: May 30, 2024 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Constants

View Source
const MinSecretKeySize = 32

Variables

View Source
var (
	ErrInvalidKey   = errors.New("key is invalid")
	ErrTokenExpired = errors.New("token is expired")
	ErrTokenInvalid = errors.New("token is invalid")
)

Functions

This section is empty.

Types

type JWTMaker

type JWTMaker struct {
	// contains filtered or unexported fields
}

JWTMaker is a JSON Web Token maker.

func (JWTMaker) GenerateAccessToken

func (maker JWTMaker) GenerateAccessToken(email, mobile, username string) (string, *OAuthClaims, error)

func (JWTMaker) GenerateRefreshToken

func (maker JWTMaker) GenerateRefreshToken(email, mobile, username string) (string, *OAuthClaims, error)

func (JWTMaker) VerifyToken

func (maker JWTMaker) VerifyToken(token string) (*OAuthClaims, error)

type OAuthClaims

type OAuthClaims struct {
	Id        string    `json:"id"`
	Email     string    `json:"email"`
	Mobile    string    `json:"mobile"`
	UserName  string    `json:"user_name"`
	IssuedAt  time.Time `json:"issued_at"`
	ExpiredAt time.Time `json:"expired_at"`
	NotBefore time.Time `json:"not_before"`
	Issuer    string    `json:"issuer,omitempty"`
}

func NewOAuthClaims

func NewOAuthClaims(email, mobile, userName, issuer string, duration time.Duration) *OAuthClaims

func (OAuthClaims) GetAudience

func (o OAuthClaims) GetAudience() (jwt.ClaimStrings, error)

func (OAuthClaims) GetExpirationTime

func (o OAuthClaims) GetExpirationTime() (*jwt.NumericDate, error)

func (OAuthClaims) GetIssuedAt

func (o OAuthClaims) GetIssuedAt() (*jwt.NumericDate, error)

func (OAuthClaims) GetIssuer

func (o OAuthClaims) GetIssuer() (string, error)

func (OAuthClaims) GetNotBefore

func (o OAuthClaims) GetNotBefore() (*jwt.NumericDate, error)

func (OAuthClaims) GetSubject

func (o OAuthClaims) GetSubject() (string, error)

func (OAuthClaims) Valid

func (o OAuthClaims) Valid() error

type OAuthConfig

type OAuthConfig struct {
	SecretKey          string `mapstructure:"secret_key" json:"secret_key" yaml:"secret_key"`
	AccessExpiresTime  string `mapstructure:"access_expires_time" json:"access_expires_time" yaml:"access_expires_time"`
	RefreshExpiresTime string `mapstructure:"refresh_expires_time" json:"refresh_expires_time" yaml:"refresh_expires_time"`
	Issuer             string `mapstructure:"issuer" json:"issuer" yaml:"issuer"`
}

type OAuthMaker

type OAuthMaker interface {
	GenerateAccessToken(email, mobile, username string) (string, *OAuthClaims, error)
	GenerateRefreshToken(email, mobile, username string) (string, *OAuthClaims, error)
	VerifyToken(token string) (*OAuthClaims, error)
}

func NewJWTMaker

func NewJWTMaker(oauthCfg OAuthConfig) (OAuthMaker, error)

NewJWTMaker creates a new JWTMaker.

func NewPasetoMaker

func NewPasetoMaker(oauthCfg OAuthConfig) (OAuthMaker, error)

NewPasetoMaker creates a new PasetoMaker.

type PasetoMaker

type PasetoMaker struct {
	// contains filtered or unexported fields
}

PasetoMaker is a PASETO maker.

func (PasetoMaker) GenerateAccessToken

func (maker PasetoMaker) GenerateAccessToken(email, mobile, username string) (string, *OAuthClaims, error)

func (PasetoMaker) GenerateRefreshToken

func (maker PasetoMaker) GenerateRefreshToken(email, mobile, username string) (string, *OAuthClaims, error)

func (PasetoMaker) VerifyToken

func (maker PasetoMaker) VerifyToken(token string) (*OAuthClaims, error)

Jump to

Keyboard shortcuts

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