Skip to content

Commit

Permalink
feat: map Scope from membership in stack token (#994)
Browse files Browse the repository at this point in the history
Co-authored-by: David Ragot <[email protected]>
  • Loading branch information
Dav-14 and David Ragot authored Dec 11, 2023
1 parent 5bf1d06 commit 69d29d0
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pkg/oidc/grant_type_bearer.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ func grantTypeBearer(issuer string, p JWTAuthorizationGrantExchanger) http.Handl
op.RequestError(w, r, err)
return
}

tokens, err := ParseAssertion(profileRequest.Assertion)
if err != nil {
op.RequestError(w, r, err)
return
}

tokenRequest.Scopes = tokens.Scopes

resp, err := CreateJWTTokenResponse(r.Context(), issuer, tokenRequest, p, client)
if err != nil {
op.RequestError(w, r, err)
Expand All @@ -116,6 +125,17 @@ func grantTypeBearer(issuer string, p JWTAuthorizationGrantExchanger) http.Handl
}
}

func ParseAssertion(assertion string) (*oidc.AccessTokenClaims, error) {
var claims = new(oidc.AccessTokenClaims)

_, err := oidc.ParseToken(assertion, claims)
if err != nil {
return nil, err
}

return claims, nil
}

func CreateJWTTokenResponse(ctx context.Context, issuer string, tokenRequest *oidc.JWTTokenRequest, creator op.TokenCreator, client op.Client) (*oidc.AccessTokenResponse, error) {
id, exp, err := creator.Storage().CreateAccessToken(ctx, tokenRequest)
if err != nil {
Expand Down

0 comments on commit 69d29d0

Please sign in to comment.