jwt

package module
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2019 License: Apache-2.0 Imports: 11 Imported by: 0

README

jwt-auth

Authenticate requests with jwt, extensible claims and a specific jwks-set.

Build Status

This library provides a way to decode a jwt-token with self-defined claims. Additionally one can specify a function to retrieve the JWKS. See here for further information about JWKS.

Installation

  • with go-get: go get github.com/fr3dch3n/jwt-auth
  • with dep: dep ensure --add github.com/fr3dch3n/jwt-auth

Usage example

Initialization

First the JWKS has to be initialized via one of the following ways:

Initialize jwk-set from json in AWS-SSM

jwt.NewAuth("/path/in/ssm", auth.FetchJwksConfigurationFromSSM)

Initialize jwk-set from local json-file

jwt.NewAuth("file/to/local/jwks.json", auth.FetchJwksConfigurationFromFS)

Authorizing requests

Then the jwt-component can be used to authenticate requests. To use specific claims, just extend the jwtgo.StandardClaims.

package handler

import (
	"fmt"
	jwtgo "github.com/dgrijalva/jwt-go"
	"github.com/fr3dch3n/jwt-auth"
	"net/http"
)

func MyAuthenticatedHandler(w http.ResponseWriter, r *http.Request) {
	authHeader := r.Header.Get("Authorization")
	token, err := jwt.DecodeToken(authHeader, &jwtgo.StandardClaims{})
	if err != nil {
	    fmt.Println(err)
	}
	fmt.Println(token)
}

Release History

  • 0.0.1
    • initial release

Meta

@fr3dch3n

Distributed under the Apache 2.0 license. See LICENSE for more information.

Contributing

  1. Fork it (https://github.com/fr3dch3n/jwt-auth/fork)
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes (git commit -am 'Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeToken

func DecodeToken(bearerToken string, claims jwt.Claims) (*jwt.Token, error)

func FetchJwksConfigurationFromFS

func FetchJwksConfigurationFromFS(jwksURL string) (*jwk.Set, error)

func FetchJwksConfigurationFromSSM

func FetchJwksConfigurationFromSSM(ssmPath string) (*jwk.Set, error)

func NewAuth

func NewAuth(jwksFetcher func(string) (*jwk.Set, error), path string, sleepDuration time.Duration)

func StopReloadingJWKS

func StopReloadingJWKS()

Types

This section is empty.

Jump to

Keyboard shortcuts

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