authenticate

package
v0.0.0-...-e92691c Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2019 License: MIT Imports: 6 Imported by: 0

README

Authenticate!

Middleware for Issuing and Validating JWTs

Dependencies:

  • dgrijalva/jwt-go
  • gorilla/context

JWT Issuer

func main() {
    Issuer := authenticate.IssueJWT(authenticate.NewIssuer(
        "My Server", //Issuer
        "", //Audience
        "Super-Secret-Secret", //JWT Signer Secret
        86400, //Expire After 1 day
        jwt.SigningMethodHMAC, //Specify signing method to use
    ))

    r := mux.NewRouter()
    r.HandleFunc("/signin", Signin) 

    http.ListenAndServe(":8000", Issuer(r))
}

func Signin(w http.ResponseWriter, r *http.Request) {
    //Do Auth stuff

    //Once you have done auth stuff call this method 
    //to store boolean isUserValid in request context
    authenticate.User(r, isUserValid) 
    return
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateAccess

func GenerateAccess(t *Token) error

GenerateAccess returns access token

func GenerateRefresh

func GenerateRefresh(t *Token) error

GenerateRefresh returns refresh token

func JWT

func JWT(validator *Validator, secure bool, fail http.Handler) func(http.Handler) http.Handler

JWT checks for authenticity of a JWT

Types

type CustomClaims

type CustomClaims struct {
	jwt.StandardClaims
}

CustomClaims ...

func NewClaim

func NewClaim(t *Token) *CustomClaims

NewClaim returns new claims

func (*CustomClaims) NewJWT

func (c *CustomClaims) NewJWT(signingMethod jwt.SigningMethod, secret []byte) (string, error)

NewJWT returns a new jwt

func (*CustomClaims) Verify

func (c *CustomClaims) Verify() error

Verify claims

type SecretFunc

type SecretFunc func(jwt.Claims) (interface{}, error)

SecretFunc ...

type Token

type Token struct {
	Access  string `json:"access"`
	Refresh string `json:"refresh"`
	// contains filtered or unexported fields
}

Token confirms if a user was authenticated

func NewToken

func NewToken(exp int64, method jwt.SigningMethod, signer []byte) *Token

NewToken ...

func (*Token) Audience

func (t *Token) Audience(aud string)

Audience tells the server who the jwt is intended for

func (*Token) Expires

func (t *Token) Expires(exp int64)

Expires sets the expire date

func (*Token) Identifier

func (t *Token) Identifier(id string)

Identifier sets the identifier for the token being issued

func (*Token) Issuer

func (t *Token) Issuer(iss string)

Issuer tells the server who issued the token

func (*Token) SignMethod

func (t *Token) SignMethod(signingMethod jwt.SigningMethod)

SignMethod sets the signing method

func (*Token) Signer

func (t *Token) Signer(signer []byte)

Signer ...

func (*Token) Subject

func (t *Token) Subject(sub string)

Subject ...

type Validator

type Validator struct {
	Claims        jwt.Claims        //Custom claim to decode into
	SigningMethod jwt.SigningMethod //SigningMethod to decode jwt
	// contains filtered or unexported fields
}

Validator expresses how the JWT should be parsed and validated

func NewValidator

func NewValidator(claims jwt.Claims, signingMethod jwt.SigningMethod, verify VerifyFunc, secret SecretFunc) *Validator

NewValidator returns initialized validator

func (*Validator) ValidateClaims

func (v *Validator) ValidateClaims() error

ValidateClaims checks claims!

func (*Validator) ValidateToken

func (v *Validator) ValidateToken(r *http.Request) error

ValidateToken retrieves and parses token to check for validity

type VerifyFunc

type VerifyFunc func(*jwt.Token) error

VerifyFunc ...

Jump to

Keyboard shortcuts

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