revert codacy

This commit is contained in:
Pascal Fischer 2023-03-30 18:54:55 +02:00
parent e08af7fcdf
commit f273fe9f51
2 changed files with 13 additions and 17 deletions

View File

@ -34,10 +34,8 @@ type AuthMiddleware struct {
audience string
}
type key string
const (
userProperty key = "user"
userProperty = "user"
)
// NewAuthMiddleware instance constructor
@ -131,10 +129,10 @@ func (m *AuthMiddleware) CheckPATFromRequest(w http.ResponseWriter, r *http.Requ
}
claimMaps := jwt.MapClaims{}
claimMaps[string(jwtclaims.UserIDClaim)] = user.Id
claimMaps[m.audience+string(jwtclaims.AccountIDSuffix)] = account.Id
claimMaps[m.audience+string(jwtclaims.DomainIDSuffix)] = account.Domain
claimMaps[m.audience+string(jwtclaims.DomainCategorySuffix)] = account.DomainCategory
claimMaps[jwtclaims.UserIDClaim] = user.Id
claimMaps[m.audience+jwtclaims.AccountIDSuffix] = account.Id
claimMaps[m.audience+jwtclaims.DomainIDSuffix] = account.Domain
claimMaps[m.audience+jwtclaims.DomainCategorySuffix] = account.DomainCategory
jwtToken := jwt.NewWithClaims(jwt.SigningMethodHS256, claimMaps)
newRequest := r.WithContext(context.WithValue(r.Context(), jwtclaims.TokenUserProperty, jwtToken))
// Update the current request with the new context information.

View File

@ -6,19 +6,17 @@ import (
"github.com/golang-jwt/jwt"
)
type key string
const (
// TokenUserProperty key for the user property in the request context
TokenUserProperty key = "user"
TokenUserProperty = "user"
// AccountIDSuffix suffix for the account id claim
AccountIDSuffix key = "wt_account_id"
AccountIDSuffix = "wt_account_id"
// DomainIDSuffix suffix for the domain id claim
DomainIDSuffix key = "wt_account_domain"
DomainIDSuffix = "wt_account_domain"
// DomainCategorySuffix suffix for the domain category claim
DomainCategorySuffix key = "wt_account_domain_category"
DomainCategorySuffix = "wt_account_domain_category"
// UserIDClaim claim for the user id
UserIDClaim key = "sub"
UserIDClaim = "sub"
)
// Extract function type
@ -81,15 +79,15 @@ func (c *ClaimsExtractor) FromToken(token *jwt.Token) AuthorizationClaims {
return jwtClaims
}
jwtClaims.UserId = userID
accountIDClaim, ok := claims[c.authAudience+string(AccountIDSuffix)]
accountIDClaim, ok := claims[c.authAudience+AccountIDSuffix]
if ok {
jwtClaims.AccountId = accountIDClaim.(string)
}
domainClaim, ok := claims[c.authAudience+string(DomainIDSuffix)]
domainClaim, ok := claims[c.authAudience+DomainIDSuffix]
if ok {
jwtClaims.Domain = domainClaim.(string)
}
domainCategoryClaim, ok := claims[c.authAudience+string(DomainCategorySuffix)]
domainCategoryClaim, ok := claims[c.authAudience+DomainCategorySuffix]
if ok {
jwtClaims.DomainCategory = domainCategoryClaim.(string)
}