refactor(auth): replace untyped JWT claims with typed Claims struct
Introduced a typed Claims struct in core/auth to replace the raw map[string]any approach used for JWT claims throughout the codebase. This provides compile-time safety and better readability when creating, validating, and extracting JWT tokens. Also upgraded lestrrat-go/jwx from v2 to v3 and go-chi/jwtauth to v5.4.0, adapting all callers to the new API where token accessor methods now return tuples instead of bare values. Updated all affected handlers, middleware, and tests. Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
+8
-4
@@ -185,12 +185,16 @@ func tokenFromHeader(r *http.Request) string {
|
||||
}
|
||||
|
||||
func UsernameFromToken(r *http.Request) string {
|
||||
token, claims, err := jwtauth.FromContext(r.Context())
|
||||
if err != nil || claims["sub"] == nil || token == nil {
|
||||
token, _, err := jwtauth.FromContext(r.Context())
|
||||
if err != nil || token == nil {
|
||||
return ""
|
||||
}
|
||||
log.Trace(r, "Found username in JWT token", "username", token.Subject())
|
||||
return token.Subject()
|
||||
sub, _ := token.Subject()
|
||||
if sub == "" {
|
||||
return ""
|
||||
}
|
||||
log.Trace(r, "Found username in JWT token", "username", sub)
|
||||
return sub
|
||||
}
|
||||
|
||||
func UsernameFromExtAuthHeader(r *http.Request) string {
|
||||
|
||||
Reference in New Issue
Block a user