auth

package
v0.0.0-...-c95cf46 Latest Latest
Warning

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

Go to latest
Published: May 14, 2018 License: MIT Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrGoogleInvalidToken is returned when google token is invalid
	ErrGoogleInvalidToken = errors.New("the token was invalid")
	// ErrGoogleError is returned when there is a problem verifiying the token from google
	ErrGoogleError = errors.New("problem verifying the token from google")
	// ErrUserParseError is returned when google sends a JSON object that is unparsable
	ErrUserParseError = errors.New("could not parse the user")
	// ErrWrongHostedDomain occurs when user's hd is not UCLA
	ErrWrongHostedDomain = errors.New("user is not part of UCLA")
)
View Source
var (
	// ErrTokenInvalid is an invalid token error
	ErrTokenInvalid = errors.New("invalid token")
	// ErrTokenWrongIssuer occurs when token has wrong issuer
	ErrTokenWrongIssuer = errors.New("token has wrong issuer")
)

Functions

func NewAuthMiddleware

func NewAuthMiddleware(LowestAuthLevelRequired int, l interfaces.Logger) echo.MiddlewareFunc

NewAuthmiddleware enforces auth on routes

func NewJWTmiddleware

func NewJWTmiddleware(t *Tokenizer, cookie string, l interfaces.Logger) echo.MiddlewareFunc

NewJWTmiddleware is an auth middleware to check JWT tokens and put its claims on the context

Types

type GoogleAuthorizer

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

GoogleAuthorizer allows for google oAuth

func NewGoogleAuthorizer

func NewGoogleAuthorizer(l interfaces.Logger) *GoogleAuthorizer

NewGoogleAuthorizer creates an authorizer for google oAuth

func (*GoogleAuthorizer) UserLogin

func (a *GoogleAuthorizer) UserLogin(token string) (*GoogleUser, error)

UserLogin is used to verify a token and parse the token from google

type GoogleUser

type GoogleUser struct {
	Sub       string `json:"sub"`
	HD        string `json:"hd"`
	Email     string `json:"email"`
	FullName  string `json:"name"`
	FirstName string `json:"given_name"`
	LastName  string `json:"family_name"`
	Picture   string `json:"picture"`
}

GoogleUser is the information provided from google

type Tokenizer

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

Tokenizer creates/parses JWT tokens

func NewTokenizer

func NewTokenizer(secret, issuer string, daysValid int, l interfaces.Logger) *Tokenizer

NewTokenizer creates a tokenizer to create/parse JWT tokens

func (*Tokenizer) NewToken

func (t *Tokenizer) NewToken(claims map[string]interface{}) (string, error)

NewToken creates a new token with the given claims

func (*Tokenizer) Validate

func (t *Tokenizer) Validate(tokenString string) (map[string]interface{}, error)

Validate checks if a token is valid and returns the token's claims

type UserClaims

type UserClaims struct {
	ID        string
	Email     string
	AuthLevel int
}

UserClaims are the claims stored in the JWT

Jump to

Keyboard shortcuts

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