Skip to content

Commit

Permalink
auth: Fix user claim name and remove client_id
Browse files Browse the repository at this point in the history
The right claim for the username is _preffered_username_.
Also, `client_id` is removed because we don't need it.

Signed-off-by: Cosmin Tupangiu <[email protected]>
  • Loading branch information
tupyy committed Dec 13, 2024
1 parent c6bcdd6 commit bc11f16
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
3 changes: 1 addition & 2 deletions internal/auth/rhsso_authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ func (rh *RHSSOAuthenticator) parseToken(userToken *jwt.Token) (User, error) {
}

return User{
Username: claims["username"].(string),
Username: claims["preffered_username"].(string),
Organization: claims["org_id"].(string),
ClientID: claims["client_id"].(string),
}, nil
}

Expand Down
6 changes: 3 additions & 3 deletions internal/auth/rhsso_authenticator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {

func generateValidToken() (string, func(t *jwt.Token) (any, error)) {
type TokenClaims struct {
Username string `json:"username"`
Username string `json:"preffered_username"`
ClientID string `json:"client_id"`
OrgID string `json:"org_id"`
jwt.RegisteredClaims
Expand Down Expand Up @@ -132,7 +132,7 @@ func generateValidToken() (string, func(t *jwt.Token) (any, error)) {

func generateInvalidValidToken(missingClaim string) (string, func(t *jwt.Token) (any, error)) {
type TokenClaims struct {
Username string `json:"username"`
Username string `json:"preffered_username"`
ClientID string `json:"client_id"`
OrgID string `json:"org_id"`
jwt.RegisteredClaims
Expand Down Expand Up @@ -176,7 +176,7 @@ func generateInvalidValidToken(missingClaim string) (string, func(t *jwt.Token)

func generateInvalidTokenWrongSigningMethod() (string, func(t *jwt.Token) (any, error)) {
type TokenClaims struct {
Username string `json:"username"`
Username string `json:"preffered_username"`
ClientID string `json:"client_id"`
OrgID string `json:"org_id"`
jwt.RegisteredClaims
Expand Down
1 change: 0 additions & 1 deletion internal/auth/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@ func newContext(ctx context.Context, u User) context.Context {
type User struct {
Username string
Organization string
ClientID string
}

0 comments on commit bc11f16

Please sign in to comment.