Skip to content

Import path: gitlab.soludian.com/soludian/fountain/libs/auth_token

auth_token

go
import "gitlab.soludian.com/soludian/fountain/libs/auth_token"

Index

Constants

go
const (
    KCookieTokenKey string = "__ac_tk"

    KTokenAuthorizedKey string = "authorized"
    KTokenAccessIDKey   string = "access_id"
    KTokenRefreshIDKey  string = "refresh_id"
    KTokenUserIDKey     string = "user_id"
    KTokenExpKey        string = "exp"
    KTokenSecureExpKey  string = "secure_exp"
    KTokenAvatarURLKey  string = "avatar_url"
    KTokenUserNameKey   string = "user_name"
    KTokenDeviceKindKey string = "device_kind"
    KTokenDeviceIPKey   string = "device_ip"

    KTokenTypeAccess  string = "access_token"
    KTokenTypeRefresh string = "refresh_token"
)

go
const (
    KCacheExpiresInOneHour  = time.Hour
    KCacheExpiresInOneDay   = 24 * KCacheExpiresInOneHour
    KCacheExpiresInOneWeek  = 7 * KCacheExpiresInOneDay
    KCacheExpiresInOneMonth = 30 * KCacheExpiresInOneDay
)

go
const KPackageName = "auth_token"

func ExtractRefreshToken

go
func ExtractRefreshToken(c fiber.Ctx, configs ...*JWTConfig) (refreshTokenID string, userID string, username string, isMobile bool, err error)

func ExtractToken

go
func ExtractToken(c fiber.Ctx, shortLive bool, configs ...*JWTConfig) (accessTokenID, userID, username, deviceKind, deviceIP, bearToken string, err error)

func GetToken

go
func GetToken(c fiber.Ctx, configs ...*JWTConfig) (token *jwt.Token, bearToken string, err error)

func Sign

go
func Sign(token *TokenDetails, signer string) (string, string, error)

type JWTConfig

go
type JWTConfig struct {
    SecretKey       string `conf:"secret_key" json:"secret_key,omitempty"`
    AccessTokenTTL  int    `conf:"access_token_ttl" json:"access_token_ttl,omitempty"`
    RefreshTokenTTL int    `conf:"refresh_token_ttl" json:"refresh_token_ttl,omitempty"`
}

type TokenDetails

go
type TokenDetails struct {
    UserID             string        `json:"user_id,omitempty"`
    UserName           string        `json:"username,omitempty"`
    DeviceKind         string        `json:"device_kind,omitempty"`
    AccessID           string        `json:"access_id,omitempty"`  // uuid.UUID, ulid or other unique string
    RefreshID          string        `json:"refresh_id,omitempty"` // uuid.UUID, ulid or other unique string
    AvatarUrl          string        `json:"avatar_url,omitempty"`
    AccessToken        *jwt.Token    `json:"-"`
    RefreshToken       *jwt.Token    `json:"-"`
    SignedAccessToken  string        `json:"signed_access_token,omitempty"`
    SignedRefreshToken string        `json:"signed_refresh_token,omitempty"`
    AtExpires          time.Duration `json:"at_expires,omitempty"`
    RtExpires          time.Duration `json:"rt_expires,omitempty"`
    SecureExpire       time.Duration `json:"secure_expire,omitempty"`
}

func NewToken

go
func NewToken(userID, username, avatar string, deviceKind string, deviceIP string, configs ...*JWTConfig) (*TokenDetails, error)

type TokenSource

go
type TokenSource interface {
    oauth2.TokenSource
    TokenCtx(context.Context) (*oauth2.Token, error)

    // Force token source to create a new token
    CreateToken() (*oauth2.Token, error)
    // Force token source to create a new token
    CreateTokenCtx(ctx context.Context) (*oauth2.Token, error)
}

Generated by gomarkdoc