auth

package
v0.0.0-...-bc28a72 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Provides the structs and function to verify and extract a token and check if the token can use the resources he wants

Index

Constants

View Source
const (
	// SuperAdminRole - Super Admin Role
	SuperAdminRole = "SuperAdmin"

	// AdminRole - Admin Role
	AdminRole = "Admin"

	// ClientRole - Client Role
	ClientRole = "Client"
)

All available roles

Variables

This section is empty.

Functions

func CreateToken

func CreateToken(clientID string, role string, appID string, expire *jwt.NumericDate) (string, error)

CreateToken - Create token with given info

func GetAuthData

func GetAuthData(request *http.Request) (string, string, bool)

GetAuthData - Get AppID and Authorization

func SetIssuer

func SetIssuer(issuer string)

func SetSecret

func SetSecret(secret string)

Types

type Identity

type Identity struct {
	Role     string
	AppID    string
	ClientID string
}

Identity - Data in JWT token

func AuthenticateAdmin

func AuthenticateAdmin(tokenString string) (*Identity, bool)

AuthenticateAdmin - Check if token is valid and is admin kind

func GetTokenAndVerify

func GetTokenAndVerify(request *http.Request, role string) (*Identity, bool)

func VerifyToken

func VerifyToken(tokenString string) (Identity, bool)

VerifyToken - Check token validity and payload

func (*Identity) CanUseAppID

func (identity *Identity) CanUseAppID(appID string) bool

CanUseAppID - Check if user can use given AppID

func (*Identity) IsAdmin

func (identity *Identity) IsAdmin() bool

IsAdmin - Check if client is admin only

func (*Identity) IsAdminKind

func (identity *Identity) IsAdminKind() bool

IsAdminKind - Check if is Super Admin or Admin

func (*Identity) IsClient

func (identity *Identity) IsClient() bool

IsClient - Check if client is not admin

func (*Identity) IsSuperAdmin

func (identity *Identity) IsSuperAdmin() bool

IsSuperAdmin - Check if client is a Super Admin

Jump to

Keyboard shortcuts

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