core_auth

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const HEADER_PREFIX = "Bearer "

Variables

This section is empty.

Functions

func AuthMiddleware

func AuthMiddleware(config *AuthConfig) gin.HandlerFunc

func CreateToken

func CreateToken(privateKey string, tokenClaims jwt.Claims) (string, error)

func ParseToken

func ParseToken(publicKey string, tokenString string, tokenClaims jwt.Claims) error

func SetAuthContext

func SetAuthContext(context *gin.Context, authContext *AuthContext)

Types

type AuthClaims

type AuthClaims struct {
	jwt.RegisteredClaims

	Name     string `json:"name,omitempty"`
	Scope    string `json:"scope,omitempty"`
	ClientId string `json:"client_id,omitempty"`
}

type AuthConfig

type AuthConfig struct {
	Enabled bool `json:"enabled" yaml:"enabled"`

	IncludeUrls []string `json:"includeUrls" yaml:"include-urls"`

	ExcludeUrls []string `json:"excludeUrls" yaml:"exclude-urls"`

	PublicKey string `json:"publicKey" yaml:"public-key"`

	PrivateKey string `json:"privateKey" yaml:"private-key"`

	TokenIssuer string `json:"tokenIssuer" yaml:"token-issuer"`

	TokenValidity int64 `json:"tokenValidity" yaml:"token-validity"`
}

type AuthContext

type AuthContext struct {
	Claims *AuthClaims

	Scopes []string
}

func GetAuthContext

func GetAuthContext(context *gin.Context) *AuthContext

func (*AuthContext) HasAndScope

func (context *AuthContext) HasAndScope(scopes ...string) bool

func (*AuthContext) HasAnyScope

func (context *AuthContext) HasAnyScope(scopes ...string) bool

func (*AuthContext) HasScope

func (context *AuthContext) HasScope(scope string) bool

Jump to

Keyboard shortcuts

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