apiauth

package
v0.0.0-...-3d294e8 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2019 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package apiauth provides persistent authorization based on boltdb.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessAuth

type AccessAuth struct {
	Username string `json:"username"`
	Address  string `json:"address"`
	Created  int64  `json:"created"`
	Expires  int64  `json:"expires"`
}

type Account

type Account struct {
	NotBefore int64  `json:"notBefore"`
	NotAfter  int64  `json:"notAfter"`
	Username  string `json:"username"`
	Password  string `json:"password,omitempty"`
}

type Authorizer

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

func Open

func Open(db *bbolt.DB, name string, config Config) (*Authorizer, error)

func (*Authorizer) AddAccount

func (a *Authorizer) AddAccount(username string, password string, notBefore time.Time, notAfter time.Time) error

func (*Authorizer) Close

func (a *Authorizer) Close() error

func (*Authorizer) CreateSession

func (a *Authorizer) CreateSession(address string, username string, password string) (*Session, error)

func (*Authorizer) ListAccounts

func (a *Authorizer) ListAccounts() ([]*Account, error)

func (*Authorizer) RefreshSession

func (a *Authorizer) RefreshSession(address string, refreshToken string) (*Session, error)

func (*Authorizer) RemoveAccount

func (a *Authorizer) RemoveAccount(username string) error

RemoveAccount revokes any authentication of an account and deletes it.

func (*Authorizer) RemoveSession

func (a *Authorizer) RemoveSession(refreshToken string) error

func (*Authorizer) VerifyAccessToken

func (a *Authorizer) VerifyAccessToken(address string, accessToken string) (string, error)

type Config

type Config struct {

	// AccessTokenLength define the length of the access token
	// used to make requests.
	AccessTokenLength int `json:"accessTokenLength"`

	// AccessDurationSeconds defines how many seconds the access token
	// will be valid.
	AccessDurationSeconds int `json:"accessDurationSeconds"`

	// RefreshTokenLength defines the length of the refresh token
	// used to continue a session.
	RefreshTokenLength int `json:"refreshTokenLength"`

	// RefreshDurationSeconds defines how many seconds the refresh token
	// will be valid.
	RefreshDurationSeconds int `json:"refreshDurationSeconds"`

	// Scrypt configuration parameters.
	Scrypt ScryptConfig `json:"scrypt"`
}

type Login

type Login struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

type RefreshAuth

type RefreshAuth struct {
	Username string `json:"username"`
	Created  int64  `json:"created"`
	Expires  int64  `json:"expires"`
}

type ScryptConfig

type ScryptConfig struct {
	// CPU/memory cost parameter (logN)
	N int `json:"n"`

	// block size parameter (octets)
	R int `json:"r"`

	// parallelisation parameter (positive int)
	P int `json:"p"`

	// bytes to use as salt (octets)
	SaltLen int `json:"saltLen"`

	// length of the derived key (octets)
	KeyLen int `json:"keyLen"`
}

func (*ScryptConfig) MemoryRequiredMB

func (s *ScryptConfig) MemoryRequiredMB() int

func (*ScryptConfig) TimeRequiredMS

func (s *ScryptConfig) TimeRequiredMS() (int, error)

type Session

type Session struct {
	AccessToken   string `json:"accessToken"`
	AccessExpire  int64  `json:"accessExpire"`
	RefreshToken  string `json:"refreshToken"`
	RefreshExpire int64  `json:"refreshExpire"`
}

Jump to

Keyboard shortcuts

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