oauthserver

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HS256 = "HS256"
	RS256 = "RS256"
)
View Source
const (
	RoleSystem        = "SYSTEM"
	RoleAdministrator = "ADMINISTRATOR"
	RoleUser          = "USER"
)

define roles in system

Variables

View Source
var (
	ErrInvalidToken = errors.New("token is invalid")
	ErrExpiredToken = errors.New("token has expired")
)

Functions

func CreateInternalToken

func CreateInternalToken(params *model.Params) string

func CreateToken

func CreateToken(params *model.Params, userDetails *model.SysApiUserDetail) (string, time.Time, error)

func Init

func Init(cfg *utils.Config)

Types

type JWTHS256Maker

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

func (*JWTHS256Maker) CreateToken

func (maker *JWTHS256Maker) CreateToken(params *model.Params, duration time.Duration, details *model.SysApiUserDetail) (string, time.Time, error)

func (*JWTHS256Maker) VerifyToken

func (maker *JWTHS256Maker) VerifyToken(token string) (*Payload, error)

type JWTRS256Maker

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

func (*JWTRS256Maker) CreateToken

func (maker *JWTRS256Maker) CreateToken(params *model.Params, duration time.Duration, details *model.SysApiUserDetail) (string, time.Time, error)

func (*JWTRS256Maker) VerifyToken

func (maker *JWTRS256Maker) VerifyToken(token string) (*Payload, error)

type JwksList

type JwksList struct {
	Keys []jwk.Key `json:"keys"`
}

func GenerateJwks

func GenerateJwks() *JwksList

type Maker

type Maker interface {
	CreateToken(params *model.Params, duration time.Duration, userDetails *model.SysApiUserDetail) (string, time.Time, error)
	VerifyToken(token string) (*Payload, error)
}

func NewJWTHS256Maker

func NewJWTHS256Maker(secretKey string) (Maker, error)

func NewJWTRS256Maker

func NewJWTRS256Maker(privateKeyPath string, publicKeyPath string, jwkId string) (Maker, error)

type OpenIdConfiguration

type OpenIdConfiguration struct {
	Issuer                string `json:"issuer"`
	AuthorizationEndpoint string `json:"authorization_endpoint"`
	JwksUri               string `json:"jwks_uri"`
}

func GenerateOpenIdConfiguration

func GenerateOpenIdConfiguration() *OpenIdConfiguration

type Payload

type Payload struct {
	Issuer   string           `json:"iss"`
	Id       uuid.UUID        `json:"jti"`
	Upn      string           `json:"upn"`
	Aud      string           `json:"aud"`
	Name     string           `json:"name,omitempty"`
	Provider string           `json:"provider,omitempty"`
	Tenant   string           `json:"tenant,omitempty"`
	IssueAt  *jwt.NumericDate `json:"iat,omitempty"`
	ExpiryAt *jwt.NumericDate `json:"exp,omitempty"`
	Roles    []string         `json:"roles,omitempty"`
}

func NewPayload

func NewPayload(params *model.Params, duration time.Duration, details *model.SysApiUserDetail) (*Payload, error)

func VerifyToken

func VerifyToken(token string) (*Payload, error)

func (*Payload) Valid

func (payload *Payload) Valid() error

Jump to

Keyboard shortcuts

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