auth

package
v1.6.10 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComparePassword

func ComparePassword(hashed string, normal string) error

func GenerateToken

func GenerateToken(username string, callbacks ...func(*Claims)) (string, error)

func HashPassword

func HashPassword(s string) string

func JwtHandler

func JwtHandler(opts ApiSecurityOptions) gin.HandlerFunc

func RefreshToken

func RefreshToken(tknStr string) (string, error)

Types

type ApiSecurityOptions

type ApiSecurityOptions struct {
	IssuerURL string   `json:"authority"`
	ClientID  string   `json:"client_id"`
	Audience  []string `json:"-"`
}

type Claims

type Claims struct {
	Username string `json:"username"`
	jwt.RegisteredClaims
}

Create a struct that will be encoded to a JWT. We add jwt.RegisteredClaims as an embedded type, to provide fields like expiry time

func ValidateToken

func ValidateToken(token string) (*Claims, error)

type CustomClaims

type CustomClaims struct {
	PreferredUsername string `json:"preferred_username"`
	EmailVerified     bool   `json:"email_verified"`
}

func (*CustomClaims) Validate

func (c *CustomClaims) Validate(ctx context.Context) error

type UserInfo

type UserInfo struct {
	Username string
}

func TokenFromContext

func TokenFromContext(ctx context.Context) *UserInfo

Jump to

Keyboard shortcuts

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