add frontend auth middleware, embed user data in frontend html

This commit is contained in:
sam 2023-09-04 17:32:45 +02:00
parent d8cb8c8fa8
commit 0fa769a248
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
12 changed files with 265 additions and 42 deletions

View file

@ -19,7 +19,7 @@ type Token struct {
ID ulid.ULID
AppID ulid.ULID
UserID ulid.ULID
Scopes []string
Scopes TokenScopes
Expires time.Time
}
@ -43,3 +43,34 @@ type TokenClaims struct {
UserID ulid.ULID `json:"sub"`
jwt.RegisteredClaims
}
type TokenScope string
const (
// All scopes below
TokenScopeAll TokenScope = "all"
TokenScopeAccountsRead TokenScope = "accounts.read"
// Controls whether tokens have access to sensitive account data, NOT if they can use `/accounts/@me` endpoints.
TokenScopeAccountsMe TokenScope = "accounts.me"
TokenScopeAccountsWrite TokenScope = "accounts.write"
)
func (s TokenScope) IsValid() bool {
switch s {
case TokenScopeAccountsRead, TokenScopeAccountsMe, TokenScopeAccountsWrite:
return true
default:
return false
}
}
type TokenScopes []TokenScope
func (s TokenScopes) Has(scope TokenScope) bool {
for i := range s {
if s[i] == scope || s[i] == TokenScopeAll {
return true
}
}
return false
}