auth

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2022 License: Apache-2.0 Imports: 12 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AccountIDCookie

func AccountIDCookie() string

AccountIDCookie is name of cookie holding account ID of signed in user

func AddTokenMD

func AddTokenMD(ctx context.Context, token string) context.Context

AddTokenMD adds token as authorization metadata to context and returns the updated context object

func DefaultAdminGroup

func DefaultAdminGroup() string

DefaultAdminGroup is the default admin group

func DefaultAdminGroups

func DefaultAdminGroups() []string

DefaultAdminGroups returns the default administrators group

func DefaultSuperAdminGroup

func DefaultSuperAdminGroup() string

DefaultSuperAdminGroup is the default super admin group

func DefaultUserGroup

func DefaultUserGroup() string

DefaultUserGroup is the default user group

func Header() string

Header returns authentication header

func JWTCookie

func JWTCookie() string

JWTCookie is name of cookie holding jwt

func RefreshCookie

func RefreshCookie() string

RefreshCookie is name of cookie holding jwt refresh token

func Scheme

func Scheme() string

Scheme returns authentication scheme

func SessionIDCookie

func SessionIDCookie() string

SessionIDCookie is name of cookie holding session ID of signed in user

Types

type API

type API interface {
	AuthenticateRequest(ctx context.Context) error
	AuthenticateRequestV2(ctx context.Context) (*Payload, error)
	AuthorizeGroup(ctx context.Context, allowedGroups ...string) (*Payload, error)
	AuthorizeActor(ctx context.Context, actorID string) (*Payload, error)
	AuthorizeActors(ctx context.Context, actorID ...string) (*Payload, error)
	AuthorizeActorAndGroup(ctx context.Context, actorID string, allowedGroups ...string) (*Payload, error)
	AuthorizeActorOrGroup(ctx context.Context, actorID string, allowedGroups ...string) (*Payload, error)
	AuthorizeAdmin(ctx context.Context) (*Payload, error)
	AuthorizeAdminStrict(ctx context.Context, adminID string) (*Payload, error)
	AdminGroups() []string
	AddAdminGroups(groups ...string)
	IsAdmin(group string) bool
	GenToken(ctx context.Context, payload *Payload, expires time.Time) (string, error)
	GenTokenUsingKey(ctx context.Context, claims *Claims, expires time.Time, signingKey []byte) (string, error)
	GenTokenFromClaims(ctx context.Context, claims *Claims, expires time.Time) (string, error)
	GetJwtPayload(ctx context.Context) (*Payload, error)
	GetPayloadFromJwt(jwt string) (*Payload, error)
	GetClaims(ctx context.Context) (*Claims, error)
	GetClaimsFromJwt(jwt string) (*Claims, error)
	GetMetadataFromJwt(jwt string) (metadata.MD, error)
	GetMetadataFromCtx(ctx context.Context) (metadata.MD, error)
	AuthorizeFunc(ctx context.Context) (context.Context, error)
}

API is the interface used for authentication and authorization

func NewAPI

func NewAPI(opt *Options) (API, error)

NewAPI creates a jwt authentication and authorization API using HS256 algorithm

type Claims

type Claims struct {
	*Payload
	jwt.StandardClaims
}

Claims contains JWT claims information

type Options

type Options struct {
	SigningMethod    jwt.SigningMethod
	SigningKey       []byte
	OtherSigningKeys [][]byte
	Issuer           string
	Audience         string
	AdminsGroup      []string
}

Options contains parameters for instantiating new API

type Payload

type Payload struct {
	ID           string
	ProjectID    string
	Names        string
	PhoneNumber  string
	EmailAddress string
	Group        string
	Roles        []string
}

Payload contains jwt payload

Jump to

Keyboard shortcuts

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