21 lines
549 B
Go
21 lines
549 B
Go
// Package clientprincipal carries an authenticated client identity, never an
|
|
// administrator or purchaser JWT. Only the client gateway sets it.
|
|
package clientprincipal
|
|
|
|
import "github.com/gin-gonic/gin"
|
|
|
|
const contextKey = "goauto.authenticatedClient"
|
|
|
|
type Identity struct {
|
|
KeyID uint64
|
|
RequestID string
|
|
AuthorizedBy uint64
|
|
}
|
|
|
|
func Set(c *gin.Context, id Identity) { c.Set(contextKey, id) }
|
|
func Get(c *gin.Context) (Identity, bool) {
|
|
v, ok := c.Get(contextKey)
|
|
id, valid := v.(Identity)
|
|
return id, ok && valid && id.KeyID > 0
|
|
}
|