auth

package
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidAPIKey       = errors.New("realm: invalid API key")
	ErrInvalidPublicAPIKey = errors.New("realm: invalid username or public API key")
	ErrInvalidPassword     = errors.New("realm: invalid password")
)

Errors related to auth

View Source
var (
	ErrInvalidToken = errors.New("the provided authentication token is invalid")
)

JWT related errors

Functions

func ValidAPIKey

func ValidAPIKey(apiKey string) bool

ValidAPIKey locally checks if the given API key is valid

func ValidAccessToken

func ValidAccessToken(accessToken string) bool

ValidAccessToken locally checks if the given access token is valid

Types

type APIKeyProvider

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

APIKeyProvider is an AuthenticationProvider using a cloud API Key

func NewAPIKeyProvider

func NewAPIKeyProvider(username, apiKey string) *APIKeyProvider

NewAPIKeyProvider returns a new APIKeyProvider given an API Key and Username

func (*APIKeyProvider) Payload

func (p *APIKeyProvider) Payload() map[string]string

Payload returns the provider's auth payload

func (*APIKeyProvider) Type

func (p *APIKeyProvider) Type() ProviderType

Type returns the auth provider type

func (*APIKeyProvider) Validate

func (p *APIKeyProvider) Validate() error

Validate will determine if a given provider is valid

type AuthenticationProvider

type AuthenticationProvider interface {
	Type() ProviderType
	Payload() map[string]string
	Validate() error
}

AuthenticationProvider represents an authentication method

type JWT

type JWT struct {
	Exp int64 `json:"exp,omitempty"`
}

JWT represents a basic auth token

func NewJWT

func NewJWT(s string) (*JWT, error)

NewJWT returns a new JWT or an error if the provided token is invalid

func (*JWT) Expired

func (jwt *JWT) Expired() bool

Expired returns a boolean representing whether or not the token is expired

type ProviderType

type ProviderType string

ProviderType represents available types of auth providers

const (
	ProviderTypeAPIKey           ProviderType = "mongodb-cloud"
	ProviderTypeUsernamePassword ProviderType = "local-userpass"
)

Available ProviderTypes

type Response

type Response struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
}

Response represents the response payload from the API containing an access token and refresh token

type UsernamePasswordProvider

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

UsernamePasswordProvider is an AuthenticationProvider using an email and password

func NewUsernamePasswordProvider

func NewUsernamePasswordProvider(username, password string) *UsernamePasswordProvider

NewUsernamePasswordProvider returns a new UsernamePasswordProvider given a username and password

func (*UsernamePasswordProvider) Payload

func (p *UsernamePasswordProvider) Payload() map[string]string

Payload returns the provider's auth payload

func (*UsernamePasswordProvider) Type

Type returns the auth provider type

func (*UsernamePasswordProvider) Validate

func (p *UsernamePasswordProvider) Validate() error

Validate will determine if a given provider is valid

Jump to

Keyboard shortcuts

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