auth

package
v0.0.0-...-0e77e91 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultUnauthorizedHandler

func DefaultUnauthorizedHandler(w http.ResponseWriter, req *http.Request)

DefaultUnauthorizedHandler :

func Time

func Time() string

Time returns a string timestamp

Types

type Activity

type Activity struct {
	LastEntry int64 `json:"lastEntry"`
}

Activity keeps the time of the last entry

type BearerGetter

type BearerGetter struct {
	Header string
}

BearerGetter :

func NewHeaderBearerTokenGetter

func NewHeaderBearerTokenGetter(header string) *BearerGetter

NewHeaderBearerTokenGetter :

func (*BearerGetter) GetTokenFromRequest

func (b *BearerGetter) GetTokenFromRequest(req *http.Request) string

GetTokenFromRequest :

type ClaimGetter

type ClaimGetter interface {
	Claims(string) interface{}
}

ClaimGetter :

type ClaimSetter

type ClaimSetter interface {
	SetClaim(string, interface{}) ClaimSetter
}

ClaimSetter :

type Credentials

type Credentials struct {
	Account  string `json:"account"`
	Password string `json:"password,omitempty"`
	Token    string `json:"token"`
	Role     string `json:"role"`
}

Credentials :

type JwtStore

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

JwtStore :

func NewJwtStore

func NewJwtStore(tokenKey string, expireAfter time.Duration) *JwtStore

NewJwtStore :

func (*JwtStore) CheckToken

func (s *JwtStore) CheckToken(token string) (Token, error)

CheckToken :

func (*JwtStore) NewToken

func (s *JwtStore) NewToken() *JwtToken

NewToken :

type JwtToken

type JwtToken struct {
	jwt.Token
	// contains filtered or unexported fields
}

JwtToken :

func (*JwtToken) Claims

func (t *JwtToken) Claims(key string) interface{}

Claims :

func (*JwtToken) Expiry

func (t *JwtToken) Expiry() time.Time

Expiry :

func (*JwtToken) IsExpired

func (t *JwtToken) IsExpired() bool

IsExpired :

func (*JwtToken) SetClaim

func (t *JwtToken) SetClaim(key string, value interface{}) ClaimSetter

SetClaim :

func (*JwtToken) String

func (t *JwtToken) String() string

String :

type Token

type Token interface {
	IsExpired() bool
	fmt.Stringer
	ClaimGetter
}

Token :

type TokenAuth

type TokenAuth struct {
	UnauthorizedHandler http.HandlerFunc
	// contains filtered or unexported fields
}

TokenAuth :

func New

func New(tokenStore *JwtStore, store ooo.Database) *TokenAuth

New :

Returns a TokenAuth object implemting Handler interface

if a handler is given it proxies the request to the handler

if a unauthorizedHandler is provided, unauthorized requests

will be handled by this HandlerFunc, otherwise a default

unauthorized handler is used.

store is the TokenStore that stores and verify the tokens

func (*TokenAuth) Audit

func (t *TokenAuth) Audit(r *http.Request) (string, string, error)

Audit : get websocket token, return token claims

func (*TokenAuth) AuditToken

func (t *TokenAuth) AuditToken(strToken string) (string, string, error)

func (*TokenAuth) Authenticate

func (t *TokenAuth) Authenticate(r *http.Request) (Token, error)

Authenticate :

func (*TokenAuth) Authorize

func (t *TokenAuth) Authorize() func(w http.ResponseWriter, r *http.Request)

Authorize will claim a token on POST and refresh the claim on PUT

func (*TokenAuth) Available

func (t *TokenAuth) Available() func(w http.ResponseWriter, r *http.Request)

Available will check if an account is taken

func (*TokenAuth) Create

func (t *TokenAuth) Create(w http.ResponseWriter, r *http.Request)

Create will create a new user (root only access)

func (*TokenAuth) NewPassword

func (t *TokenAuth) NewPassword(w http.ResponseWriter, r *http.Request)

NewPassword is for updating account password

func (*TokenAuth) Profile

func (t *TokenAuth) Profile() func(w http.ResponseWriter, r *http.Request)

Profile returns to the client the correspondent user profile for the token provided

func (*TokenAuth) Register

func (t *TokenAuth) Register(w http.ResponseWriter, r *http.Request)

Register will create a new user with the default user role (open route)

func (*TokenAuth) Routes

func (t *TokenAuth) Routes(server *ooo.Server)

Routes handle for auth enpoints

func (*TokenAuth) User

func (t *TokenAuth) User(w http.ResponseWriter, r *http.Request)

User will send the user list to a root user

func (*TokenAuth) Users

func (t *TokenAuth) Users() func(w http.ResponseWriter, r *http.Request)

Users will send the user list to a root user

func (*TokenAuth) Verify

func (t *TokenAuth) Verify(req *http.Request) bool

Verify : wrap a HandlerFunc to be authenticated

type TokenGetter

type TokenGetter interface {
	GetTokenFromRequest(req *http.Request) string
}

TokenGetter :

type User

type User struct {
	Name     string `json:"name"`
	Account  string `json:"account"`
	Password string `json:"password,omitempty"`
	Role     string `json:"role"`
}

User :

Jump to

Keyboard shortcuts

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