Fix user-id claim parsing

This commit is contained in:
Denis Arh
2022-01-22 21:47:36 +01:00
parent f53463a32d
commit 6c7d89a921
3 changed files with 12 additions and 11 deletions
+7 -10
View File
@@ -46,16 +46,13 @@ func (i identity) String() string {
func ExtractFromSubClaim(sub string) (userID uint64, rr []uint64) {
parts := strings.Split(sub, " ")
if len(parts) > 1 {
rr = make([]uint64, len(parts)-1)
for p := range parts {
id, _ := strconv.ParseUint(parts[p], 10, 64)
if p == 0 {
userID = id
} else {
rr[p-1] = id
}
rr = make([]uint64, len(parts)-1)
for p := range parts {
id, _ := strconv.ParseUint(parts[p], 10, 64)
if p == 0 {
userID = id
} else {
rr[p-1] = id
}
}
+4
View File
@@ -223,6 +223,10 @@ func makeToken(req *TokenRequest) (_ jwt.Token, err error) {
// IdentityFromToken decodes sub & roles claims into identity
func IdentityFromToken(token jwt.Token) *identity {
if token == nil {
return Anonymous()
}
var (
roles, _ = token.Get("roles")
)
+1 -1
View File
@@ -44,7 +44,7 @@ func HttpTokenValidator(scope ...string) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
token, err := verifyToken(r.Context(), TokenIssuer, scope...)
if err != nil {
if err != nil && !errors.Is(err, jwtauth.ErrNoTokenFound) {
errors.ProperlyServeHTTP(w, r, err, false)
return
}