auth

package
v0.0.0-...-db51e23 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthMiddleware

func AuthMiddleware(optional bool, next http.Handler) http.HandlerFunc

Authn middleware

func AuthzStash

func AuthzStash(
	database database.DB,
	next http.Handler,
) http.HandlerFunc

Authz middleware that allows access either if user owns this stash, or the stash is public. Takes in stash from the url path.

func GenerateJWT

func GenerateJWT(UserId int, email string) (string, error)

Generate Jwt to be used for urlstash

func GetPayload

func GetPayload(tokenStr []byte) (*idtoken.Payload, error)

Function for extracting payload from google identity's jwt

func Login

func Login(tokenStr []byte, db database.DB) (*string, error)

Accepts Google identity's JWT, parse and upsert user into db, Return a new generated Jwt for urlstash

Types

type ContextKey

type ContextKey string

Context key/val pair

type ContextVal

type ContextVal struct {
	UserId int
	Email  string
}

func ParseJWT

func ParseJWT(tokenStr string) (*ContextVal, error)

type CustomClaims

type CustomClaims struct {
	UserId int `json:"uid"`
	jwt.RegisteredClaims
}

Custom jwt claims for urlstash

type GoogleData

type GoogleData struct {
	Username string
	Name     string
	Email    string
	Picture  string
}

Useful data from Google's JWT

func GetData

func GetData(p *idtoken.Payload) *GoogleData

Extract data from google jwt's payload

Jump to

Keyboard shortcuts

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