totp

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2018 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CompletedHandler

type CompletedHandler interface {
	SecondFactorCompleted(userid, action string)
}

CompletedHandler Callback for 2fa signature completion

type Controller

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

Controller TOTP controller instance

func NewController

func NewController(issuerName string, totpStore Storer, emitter events.Emitter) *Controller

NewController creates a new TOTP controller TOTP tokens are issued against the provided issuer name and user email account. A CompletedHandler is required for completion of authorization actions, as welll as a Storer to provide underlying storage to the TOTP module

func (*Controller) BindAPI

func (totpModule *Controller) BindAPI(router *web.Router)

BindAPI Binds the API for the totp module to the provided router

func (*Controller) CreateToken

func (totpModule *Controller) CreateToken(userid string) (*otp.Key, error)

CreateToken creates a TOTP token for the provided account

func (*Controller) IsSupported

func (totpModule *Controller) IsSupported(userid string) bool

IsSupported Checks whether totp is supported for a given user by userid This is required to implement the generic 2fa interface for binding into the core module.

func (*Controller) ListTokens

func (totpModule *Controller) ListTokens(userid string) ([]TokenResp, error)

ListTokens lists tokens for a given user

func (*Controller) RemoveToken

func (totpModule *Controller) RemoveToken(userid, tokenID string) (bool, error)

RemoveToken removes a token by matching user and token external IDs

func (*Controller) ValidateRegistration

func (totpModule *Controller) ValidateRegistration(userid, tokenName, secret, token string) (bool, error)

ValidateRegistration validates a totp token registration for a given user and enrols the token if valid

func (*Controller) ValidateToken

func (totpModule *Controller) ValidateToken(userid string, token string) (bool, error)

ValidateToken validates a totp token for a given user This is used to check a user provided token against the set of registered totp keys

type RegisterChallenge

type RegisterChallenge struct {
	AccountName string
	Issuer      string
	TokenName   string
	URL         string
	Image       string
	Secret      string
}

RegisterChallenge is a TOTP registration challenge

type Storer

type Storer interface {
	// Fetch a user instance by user id (should be able to remove this)
	GetUserByExtID(userid string) (interface{}, error)
	// Add a totp token to a given user
	AddTotpToken(userid, name, secret string, counter uint) (interface{}, error)
	// Fetch totp tokens for a given user
	GetTotpTokens(userid string) ([]interface{}, error)
	// Update a provided totp token
	UpdateTotpToken(token interface{}) (interface{}, error)
	// Remove a totp token
	RemoveTotpToken(token interface{}) error
}

Storer Token store interface This must be implemented by a storage module to provide persistence to the module

type TokenInterface

type TokenInterface interface {
	GetExtID() string
	GetName() string
	GetSecret() string
	GetCounter() uint
	SetCounter(uint)
	GetLastUsed() time.Time
	SetLastUsed(time.Time)
}

TokenInterface Token instance interface Storer token objects must implement this interface

type TokenResp

type TokenResp struct {
	ExtID      string
	Name       string
	LastUsed   time.Time
	UsageCount uint
}

TokenResp is a sanatised token instance to return from the controller

type User

type User interface {
	GetEmail() string
}

User interface type Storer user objects must implement this interface

Jump to

Keyboard shortcuts

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