auth

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2020 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Endpoint is the base of the auth URL
	Endpoint = "auth"
)

Variables

View Source
var (
	// TokenLifespan is how long a token lives before it expires
	TokenLifespan = time.Hour * 12

	// ErrNoToken is returned by GetToken if no token is provided
	ErrNoToken = errors.New("auth token not provided")
)

Functions

func NewService

func NewService(log logging.Logger, auth *Auth) *common.HTTPHandler

NewService returns a new auth API service

Types

type Auth

type Auth struct {
	Enabled  bool          // True iff API calls need auth token
	Password password.Hash // Hash of the password. Can be changed via API call.
	// contains filtered or unexported fields
}

Auth handles HTTP API authorization for this node

func (*Auth) WrapHandler

func (auth *Auth) WrapHandler(h http.Handler) http.Handler

WrapHandler wraps a handler. Before passing a request to the handler, check that an auth token was provided (if necessary) and that it is valid/unexpired.

type ChangePasswordArgs

type ChangePasswordArgs struct {
	OldPassword string `json:"oldPassword"` // Current authorization password
	NewPassword string `json:"newPassword"` // New authorization password
}

ChangePasswordArgs ...

type NewTokenArgs

type NewTokenArgs struct {
	Password
	// Endpoints that may be accessed with this token
	// e.g. if endpoints is ["/ext/bc/X", "/ext/admin"] then the token holder
	// can hit the X-Chain API and the admin API
	// If [Endpoints] contains an element "*" then the token
	// allows access to all API endpoints
	// [Endpoints] must have between 1 and [maxEndpoints] elements
	Endpoints []string `json:"endpoints"`
}

NewTokenArgs ...

type Password

type Password struct {
	Password string `json:"password"` // The authorization password
}

Password ...

type RevokeTokenArgs

type RevokeTokenArgs struct {
	Password
	Token
}

RevokeTokenArgs ...

type Service

type Service struct {
	*Auth // has to be a reference to the same Auth inside the API server
	// contains filtered or unexported fields
}

Service ...

func (*Service) ChangePassword

func (s *Service) ChangePassword(_ *http.Request, args *ChangePasswordArgs, reply *Success) error

ChangePassword changes the password required to create and revoke tokens Changing the password makes tokens issued under a previous password invalid

func (*Service) NewToken

func (s *Service) NewToken(_ *http.Request, args *NewTokenArgs, reply *Token) error

NewToken returns a new token

func (*Service) RevokeToken

func (s *Service) RevokeToken(_ *http.Request, args *RevokeTokenArgs, reply *Success) error

RevokeToken revokes a token

type Success

type Success struct {
	Success bool `json:"success"`
}

Success ...

type Token

type Token struct {
	Token string `json:"token"` // The new token. Expires in [TokenLifespan].
}

Token ...

Jump to

Keyboard shortcuts

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