apptoken

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2016 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidToken = errors.New("invalid token")

ErrInvalidToken error returned when token cannot be parsed.

Functions

func NewEmailTokenString

func NewEmailTokenString(
	issuer, login, email, passwordHash string,
	expiration time.Duration,
	signKey []byte) (string, error)

NewEmailTokenString creates new jwt token and converts it to signed string. It may be used to create password reset URL for confirmation email.

func NewStateTokenString

func NewStateTokenString(
	issuer, providerID string,
	expiration time.Duration,
	signKey []byte) (string, error)

NewStateTokenString creates new jwt token and converts it to signed string. It can be used to create state token for OAuth2 code flow.

func NewStateWithLoginTokenString

func NewStateWithLoginTokenString(
	issuer, providerID, login string,
	expiration time.Duration,
	signKey []byte) (string, error)

NewStateWithLoginTokenString creates new jwt token and converts it to signed string. It can be used to create state token for OAuth2 code flow. This method additionally packs login into token, which is useful in case of login/password authentication via application's own login form.

Types

type EmailToken

type EmailToken interface {

	// Login returns user's login.
	Login() string

	// Email returns users's email which token was issued for.
	Email() string

	// PasswordHash returns the hash of the password.
	// Password hash goes into the token and then into the link, which is
	// included into the email for the user. When the user follow the link,
	// the token is returned to the server in the url param and the hash is
	// used to check if the password has not been changed yet.
	PasswordHash() string
}

EmailToken represents token, used to be sent in confirmation email.

func ParseEmailToken

func ParseEmailToken(
	issuer, token string,
	signKey []byte) (EmailToken, error)

ParseEmailToken can parse jwt tokens from strings created by NewEmailTokenString.

type StateToken

type StateToken interface {

	// ProviderID is an ID of OAuth2 provider, used to initiate auth request.
	ProviderID() string

	// User's login if known at state creation (like in case of form-based auth)
	Login() string
}

StateToken represents state token.

func ParseStateToken

func ParseStateToken(
	issuer, token string,
	signKey []byte) (StateToken, error)

ParseStateToken can parse jwt tokens from strings created by NewStateTokenString or NewStateWithLoginTokenString.

Jump to

Keyboard shortcuts

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