feat: Added basic user authorization
This commit is contained in:
38
modules/jwt/claims.go
Normal file
38
modules/jwt/claims.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package jwt
|
||||
|
||||
import (
|
||||
"os"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
)
|
||||
|
||||
type Claims struct {
|
||||
*jwt.RegisteredClaims
|
||||
|
||||
UserID uint64 `json:"userId"`
|
||||
}
|
||||
|
||||
func NewClaims() *Claims {
|
||||
c := &Claims{
|
||||
RegisteredClaims: &jwt.RegisteredClaims{},
|
||||
}
|
||||
|
||||
var (
|
||||
trustedHosts = os.Getenv("JWT_TRUSTED_HOSTS")
|
||||
audienceList []string
|
||||
)
|
||||
|
||||
c.Issuer = os.Getenv("APP_HOST")
|
||||
|
||||
audienceList = append(audienceList, strings.Split(trustedHosts, ",")...)
|
||||
audienceList = append(audienceList, c.Issuer)
|
||||
audienceList = slices.DeleteFunc(audienceList, func(s string) bool {
|
||||
return s == ""
|
||||
})
|
||||
|
||||
c.Audience = audienceList
|
||||
|
||||
return c
|
||||
}
|
||||
Reference in New Issue
Block a user