auth

package
v0.0.0-...-ab897cc Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2020 License: MPL-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoToken = errors.New("no token")

Functions

This section is empty.

Types

type AddUserScopesArgs

type AddUserScopesArgs struct {
	User   string
	Scopes []string
	Auto   bool
}

type Auth

type Auth struct {
	URL       string
	AuthToken string // either a service token string, user token string, or empty.
	Log       interface {
		Println(v ...interface{})
		Printf(format string, v ...interface{})
	}
	// contains filtered or unexported fields
}

func (*Auth) AddUserScopes

func (auth *Auth) AddUserScopes(ctx context.Context, args AddUserScopesArgs) error

func (*Auth) Authorization

func (auth *Auth) Authorization(r *http.Request) (*Token, error)

Authorization gets the token from the Authorization header, passes it to GetToken. Returns ErrNoToken if the expected token is not present.

func (*Auth) CreateKey

func (auth *Auth) CreateKey(ctx context.Context, args CreateKeyArgs) (*TokenResult, error)

func (*Auth) GetToken

func (auth *Auth) GetToken(ctx context.Context, tokenString string) (*Token, error)

GetToken reads tokenString, returns a validated *Token, or error. The error can be of type *InvalidTokenError, *CallError, *url.Error, or other.

func (*Auth) GetUser

func (auth *Auth) GetUser(ctx context.Context, args GetUserArgs) (*GetUserResult, error)

func (*Auth) GetUserScopes

func (auth *Auth) GetUserScopes(ctx context.Context, args GetUserScopesArgs) (*GetUserScopesResult, error)

func (*Auth) Invalidate

func (auth *Auth) Invalidate(ctx context.Context, args InvalidateArgs) error

func (*Auth) Login

func (auth *Auth) Login(ctx context.Context, args LoginArgs) (*TokenResult, error)

func (*Auth) PublicKey

func (auth *Auth) PublicKey(ctx context.Context) (interface{}, error)

PublicKey gets the public key from the auth service.

func (*Auth) Signup

func (auth *Auth) Signup(ctx context.Context, args SignupArgs) (*TokenResult, error)

func (*Auth) UpdateUser

func (auth *Auth) UpdateUser(ctx context.Context, args UpdateUserArgs) error

func (*Auth) Validate

func (auth *Auth) Validate(ctx context.Context, args ValidateArgs) (*TokenResult, error)

type CallError

type CallError struct {
	Msg            string
	HTTPStatus     string
	HTTPStatusCode int
	ScopeRequired  string
	IsUserError    bool
}

CallError is a generic API call error from a failed HTTP request.

func NewCallError

func NewCallError(resp *http.Response) *CallError

NewCallError creates a *CallError from the HTTP Response, or nil if the status is 200. The body should not be read yet, this call reads the body if the result is not nil. The caller needs to close the body sometime after this call.

func (*CallError) Error

func (err *CallError) Error() string

type CreateKeyArgs

type CreateKeyArgs struct {
	Duration    time.Duration // optional
	Name        string        // optional
	Scopes      []string
	CanonScopes []string // optional
}

type GetUserArgs

type GetUserArgs struct {
	User string
}

type GetUserResult

type GetUserResult struct {
	ID     int64  `json:"id"`
	Name   string `json:"name"`
	Email  string `json:"email"`
	Scopes Scopes `json:"scopes"`
}

type GetUserScopesArgs

type GetUserScopesArgs struct {
	User string
}

type GetUserScopesResult

type GetUserScopesResult struct {
	Name   string `json:"name"`
	Scopes Scopes `json:"scopes"`
}

type InvalidTokenError

type InvalidTokenError struct {
	*jwt.ValidationError
}

func (*InvalidTokenError) Expired

func (err *InvalidTokenError) Expired() bool

func (*InvalidTokenError) Unwrap

func (err *InvalidTokenError) Unwrap() error

type InvalidateArgs

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

type LoginArgs

type LoginArgs struct {
	Duration time.Duration // optional
	Request  []string
	Demand   []string
	Allow    []string // optional
	Deny     []string // optional
	Username string
	Password string
	LoginBody
}

type LoginBody

type LoginBody struct {
	ExchangeToken string `json:"exchange,omitempty"`
}

type Scopes

type Scopes []string

func GetTokenScopes

func GetTokenScopes(tok *Token) Scopes

GetTokenScopes gets the Scopes from the Token. Only guaranteed to work on tokens returned by Auth.

func (Scopes) Has

func (s Scopes) Has(scope string) bool

func (Scopes) IsMaster

func (s Scopes) IsMaster() bool

func (Scopes) IsService

func (s Scopes) IsService() bool

func (Scopes) IsUser

func (s Scopes) IsUser() bool

func (Scopes) MarshalText

func (s Scopes) MarshalText() ([]byte, error)

func (*Scopes) UnmarshalText

func (s *Scopes) UnmarshalText(text []byte) error

func (Scopes) Valid

func (s Scopes) Valid() bool

type SignupArgs

type SignupArgs struct {
	NoPassword bool
	AnyEmail   bool
	SignupBody
}

type SignupBody

type SignupBody struct {
	Username string `json:"username"`
	Email    string `json:"email"`
	Password string `json:"password"`
}

type Token

type Token = jwt.Token

type TokenClaims

type TokenClaims = jwt.MapClaims

type TokenResult

type TokenResult struct {
	Token    string `json:"token"`
	Name     string `json:"name"`
	Scopes   Scopes `json:"scopes"`
	Valid    bool   `json:"valid"`
	Exchange string `json:"exchange,omitempty"`
}

type UpdateUserArgs

type UpdateUserArgs struct {
	UpdateUserBody
}

type UpdateUserBody

type UpdateUserBody struct {
	Updates map[string]interface{} `json:"updates"`
}

type ValidateArgs

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

Jump to

Keyboard shortcuts

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