auth

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2017 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AuthorizationHeader   = "authorization" // HTTP2 authorization header name, cf. https://http2.github.io/http2-spec/compression.html#static.table.definition
	AuthorizationScheme   = "amp"
	TokenKey              = "amp.token"
	UserKey               = "amp.user"
	ActiveOrganizationKey = "amp.organization"
	CredentialsRequired   = "credentials required"
)

Keys used in context metadata

View Source
const (
	TokenIssuer           = "amplifier"
	TokenTypeVerification = "verification"
	TokenTypeLogin        = "login"
	TokenTypePassword     = "password"

	VerificationTokenValidFor = time.Hour
	LoginTokenValidFor        = 24 * time.Hour
	PasswordTokenValidFor     = time.Hour
)

Token constants

Variables

This section is empty.

Functions

func ForgeAuthorizationHeader added in v0.10.0

func ForgeAuthorizationHeader(token string) string

ForgeAuthorizationHeader forges an amp authorization header

func GetActiveOrganization

func GetActiveOrganization(ctx context.Context) string

GetActiveOrganization gets the active organization from context metadata

func GetUser

func GetUser(ctx context.Context) string

GetUser gets the user from context metadata

Types

type AuthClaims added in v0.9.1

type AuthClaims struct {
	Type               string `json:"Type"`
	AccountName        string `json:"AccountName"`
	ActiveOrganization string `json:"ActiveOrganization"`
	jwt.StandardClaims
}

AuthClaims represents authentication claims

type Interceptors added in v0.12.0

type Interceptors struct {
	Tokens      *Tokens
	IsUserValid ValidateUser
}

func (*Interceptors) Interceptor added in v0.12.0

func (i *Interceptors) Interceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (h interface{}, err error)

Interceptor is an interceptor checking for authentication tokens

func (*Interceptors) StreamInterceptor added in v0.12.0

func (i *Interceptors) StreamInterceptor(srv interface{}, stream grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error

StreamInterceptor is an interceptor checking for authentication tokens

type Tokens added in v0.12.0

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

func New added in v0.12.0

func New(secretKey string) *Tokens

func (*Tokens) CreateLoginToken added in v0.12.0

func (t *Tokens) CreateLoginToken(name string, activeOrganization string) (string, error)

CreateLoginToken creates a login token for a given account

func (*Tokens) CreatePasswordToken added in v0.12.0

func (t *Tokens) CreatePasswordToken(name string) (string, error)

CreatePasswordToken creates a password token for a given user name

func (*Tokens) CreateVerificationToken added in v0.12.0

func (t *Tokens) CreateVerificationToken(name string) (string, error)

CreateVerificationToken creates a verification token for a given user

func (*Tokens) ValidateToken added in v0.12.0

func (t *Tokens) ValidateToken(signedString string, tokenType string) (*AuthClaims, error)

ValidateToken validates a token and return its claims

type ValidateUser added in v0.13.0

type ValidateUser func(string) bool

Jump to

Keyboard shortcuts

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