goliauth

package module
v0.0.0-...-605cfb9 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2021 License: MIT Imports: 9 Imported by: 0

README

A simple JWT Auth CLI written in Golang

Notes: this is not intended to be a CLI tool but rather an example to show how to make one.

This is the code to accompany with my three-part tutorial on JWT Authentication with Golang. Please see the tutorial here https://medium.com/@stle/simple-jwt-authentication-for-golang-part-1-6f314b456aa

To download this repo, simply run

go get github.com/omnisyle/goliauth

Please run

goliauth help

to see all available commands.

API Doc can be found at https://godoc.org/github.com/omnisyle/goliauth

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthenticateJWTMiddleware

func AuthenticateJWTMiddleware(next http.Handler, secretKey string) http.Handler

AuthenticateJWTMiddleware wraps AuthenticateJWTToken to provide middleware this is just an example to show how it can be used as a middleware

func AuthenticateJWTToken

func AuthenticateJWTToken(secretKey string, req *http.Request) (map[string]interface{}, error)

AuthenticateJWTToken is the main function to verify the JWT token from a request and it returns the claims

func Decrypt

func Decrypt(encryptedKey []byte) ([]byte, error)

Decrypt will return the original value of the encrypted string

func EncodeJWT

func EncodeJWT(secretKey string, claims Claims) (string, error)

EncodeJWT serialize data into a jwt token using a secret This secret must match with the client's secret who's generating the token

func Encrypt

func Encrypt(key []byte) ([]byte, error)

Encrypt will encrypt a raw string to an encrypted value an encrypted value has an IV (nonce) + actual encrypted value when we decrypt, we only decrypt the latter part

func ExtractJWTToken

func ExtractJWTToken(req *http.Request) (string, error)

ExtractJWTToken extracts bearer token from Authorization header

func NewRandomKey

func NewRandomKey() []byte

NewRandomKey will generate a 32 bytes random string

Types

type Claims

type Claims = jwt.MapClaims

Claims is an alias for MapClaims

func NewClaims

func NewClaims(data map[string]interface{}) Claims

NewClaims create a Claims type

func ParseJWT

func ParseJWT(tokenString string, key string) (Claims, error)

ParseJWT parses a JWT and returns Claims object Claims can be access using index notation such as claims["foo"]

type StandardClaims

type StandardClaims jwt.StandardClaims

StandardClaims wraps jwt standard claims type

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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