auth

package
v0.0.0-...-07a1cdb Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ForgeToken

func ForgeToken(uid, email, role string, level int, key *rsa.PrivateKey, customClaims jwt.MapClaims) (string, error)

ForgeToken creates a valid JWT signed by the given private key

Types

type APIKeyHMAC

type APIKeyHMAC struct {
	AccessKey string
	SecretKey string
}

APIKeyHMAC contains API keys credential to authenticate to HTTP API using HMAC

func NewAPIKeyHMAC

func NewAPIKeyHMAC(accessKey, secretKey string) *APIKeyHMAC

NewAPIKeyHMAC creates an instance of APIKeyHMAC

func (*APIKeyHMAC) GetSignature

func (key *APIKeyHMAC) GetSignature(nonce int64) string

GetSignature return a signature for the given nonce, if nonce is zero it use the current time in millisecond

func (*APIKeyHMAC) GetSignedHeader

func (key *APIKeyHMAC) GetSignedHeader(nonce int64) http.Header

GetSignedHeader returns a header with valid HMAC authorization fields

type Auth

type Auth struct {
	UID        string      `json:"uid"`
	State      string      `json:"state"`
	Email      string      `json:"email"`
	Role       string      `json:"role"`
	ReferralID json.Number `json:"referral_id"`
	Level      json.Number `json:"level"`
	Audience   []string    `json:"aud,omitempty"`

	jwt.StandardClaims
}

Auth struct represents parsed jwt information.

func ParseAndValidate

func ParseAndValidate(token string, key *rsa.PublicKey) (Auth, error)

ParseAndValidate parses token and validates it's jwt signature with given key.

type KeyStore

type KeyStore struct {
	PublicKey  *rsa.PublicKey
	PrivateKey *rsa.PrivateKey
}

func LoadOrGenerateKeys

func LoadOrGenerateKeys(privPath, pubPath string) (*KeyStore, error)

func (*KeyStore) GenerateKeys

func (ks *KeyStore) GenerateKeys() error

func (*KeyStore) LoadPrivateKey

func (ks *KeyStore) LoadPrivateKey(path string) error

func (*KeyStore) LoadPublicKeyFromFile

func (ks *KeyStore) LoadPublicKeyFromFile(path string) error

func (*KeyStore) LoadPublicKeyFromString

func (ks *KeyStore) LoadPublicKeyFromString(str string) error

func (*KeyStore) SavePrivateKey

func (ks *KeyStore) SavePrivateKey(path string) error

func (*KeyStore) SavePublicKey

func (ks *KeyStore) SavePublicKey(path string) error

Jump to

Keyboard shortcuts

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