auth

package module
v0.0.0-...-e53d96d Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2020 License: MIT Imports: 8 Imported by: 0

README

go-jwt-auth

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateJWT

func GenerateJWT(claims JWTClaims, expiryInMinutes int) (string, error)

GenerateJWT used to generate a JWT based on the given claims and expiry in minutes

func RefreshJWT

func RefreshJWT(tokenToRefreshStr string, expiryInMinutes int) (string, error)

RefreshJWT used to refresh a valid JWT expiry in minutes

Types

type Handler

type Handler struct {
	Path                string
	Handler             func(http.ResponseWriter, *http.Request)
	Permissions         Type
	RequestedResourceID string
}

Handler represents a protected route

func (Handler) ServeHTTP

func (ah Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type JWTClaims

type JWTClaims struct {
	Username    string              `json:"username"`
	Type        string              `json:"type"`
	Permissions map[string][]string `json:"permissions"`
	jwt.StandardClaims
}

JWTClaims represents the claims in the JWT

type Type

type Type uint64

Type representing the required level (need to be admin, user, service account) to access a resource

const (
	// AuthTypeUser means that a user account is required to access a resource
	AuthTypeUser Type = 1 << iota

	// AuthTypeAdmin means that an admin account is required to access a resource
	AuthTypeAdmin Type = 2

	// AuthTypeServiceAccount means that a service account is required to access a resource
	AuthTypeServiceAccount Type = 4

	// AuthTypeAll means that any account type can access the ressource (anonymous not allowed)
	AuthTypeAll Type = 8
)

func (Type) HasFlag

func (t Type) HasFlag(flag Type) bool

HasFlag is useful to check if the current route got the specific user flag We can protect a route like AuthTypeAdmin | AuthTypeServiceAccount, it should then allow only those two types

Jump to

Keyboard shortcuts

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