bearskin

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2020 License: MIT Imports: 2 Imported by: 0

README

bearskin-validator

Bearskin is the name of my authentication service. The main bearskin repository is currently private, but might become public some time in the future.

Bearskin generates a JWT token with some claims based on pre-stored information. This is done when a login endpoint is called with a correct set of credentials. The JWT token can only be generated by Bearskin service because it's the only one who knows the private key, but the tokens can be verified by anyone who got the public key.

This library will provide the functionality, and a structured way to validate a JWT token generated by Bearskin. Other services can validate and retrieve the claims without the need of making a call to the Bearskin service.

Example:

claims, err := bearskin.GetClaimsFromVerifiedJwt(PUBLIC_KEY, JWT_TOKEN)

If the JWT token is invalid or there was a problem with the parsing, the claims will be nil, and an error will be returned.
If the JWT token is valid, claims will be of type bearskin.Claims struct with the information from the token, and err will be nil.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Claims

type Claims struct {
	jwt.StandardClaims
	UserID      string   `json:"user-id"`
	Permissions []string `json:"permissions"`
}

Claims are the information that is stored inside a token. If the token was verified correctly, these claims represent the truth.

func GetClaimsFromVerifiedJwt

func GetClaimsFromVerifiedJwt(publicKey, tokenString string) (*Claims, error)

GetClaimsFromVerifiedJwt will return the claims if the token is valid. If the token is invalid, nil is returned along with an error.

type UnauthorizedError added in v0.0.3

type UnauthorizedError struct {
	Message string
}

UnauthorizedError is used when the token is invalid, or there was some other error while parsing the claim.

func (UnauthorizedError) Error added in v0.0.3

func (ue UnauthorizedError) Error() string

Jump to

Keyboard shortcuts

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