jwt

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2020 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTokenExpired represents the error if the JWT token is expired.
	ErrTokenExpired = errors.New("Token is either expired or not active yet")
)

Functions

This section is empty.

Types

type AuthProvider

type AuthProvider struct {
	// Secret is the JWT secret used to issue the tokens.
	Secret []byte
	// contains filtered or unexported fields
}

AuthProvider is the authentication provider for JWT, it contains functions to issue, validate and refresh tokens using the JWT secret embedded.

func NewJWTAuthProvider

func NewJWTAuthProvider(secret string) *AuthProvider

NewJWTAuthProvider returns a new instance of Authentication provider with the specified secret used for all relevant purposes.

func (*AuthProvider) GetServerClaimsFromToken

func (j *AuthProvider) GetServerClaimsFromToken(token string) (*ServerClaims, error)

GetServerClaimsFromToken parses the token against a server claims provided in the string, returns an error if there is any issue with the token else populate the claim object with the provided fields.

func (*AuthProvider) GetUserClaimsFromToken

func (j *AuthProvider) GetUserClaimsFromToken(token string) (*UserClaims, error)

GetUserClaimsFromToken parses the token provided in the string, returns an error if there is any issue with the token else populate the claim object with the provided fields.

func (*AuthProvider) NewAuthToken

func (j *AuthProvider) NewAuthToken(email, name string) (string, error)

NewAuthToken issues a new JWT authentication token to be used for the provided user email.

func (*AuthProvider) NewServerAuthToken

func (j *AuthProvider) NewServerAuthToken(address, name string) (string, error)

NewServerAuthToken issues a new JWT authentication token to be used for the provided server name and address.

type ServerClaims

type ServerClaims struct {
	Address string `json:"address"`
	Name    string `json:"name"`

	jwt.StandardClaims
}

ServerClaims are the claims that a server uses to establish its identity while communication with a peer server.

type UserClaims

type UserClaims struct {
	Email string `json:"email"`
	Name  string `json:"name"`

	// Roles contains the roles assumed by the user.
	Roles []string `json:"roles"`

	jwt.StandardClaims
}

UserClaims are the claims that are verified in the jwt token. Email is the email of the user associated with the claim. The Claim type also includes default jwt standard claims.

Jump to

Keyboard shortcuts

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