Skip to content

Commit f554449

Browse files
committed
fix: remove reliance on access token and fix signature of client credentials oid provider
1 parent bbe9982 commit f554449

3 files changed

Lines changed: 12 additions & 26 deletions

File tree

client/client.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -222,26 +222,18 @@ func (o *OpkClient) oidcAuth(
222222
if err != nil {
223223
return nil, fmt.Errorf("error requesting OIDC tokens from OpenID Provider: %w", err)
224224
}
225-
providerToken := tokens.IDToken
226-
if len(providerToken) == 0 {
227-
if _, ok := o.Op.(providers.ClientCredentialsOpenIdProvider); ok && len(tokens.AccessToken) > 0 {
228-
providerToken = tokens.AccessToken
229-
}
230-
}
231-
if len(providerToken) == 0 {
232-
return nil, fmt.Errorf("provider response missing ID token")
233-
}
225+
idToken := tokens.IDToken
234226
o.refreshToken = tokens.RefreshToken
235227
o.accessToken = tokens.AccessToken
236228

237229
// Sign over the payload from the ID token and client instance claims
238-
cicToken, err := cic.Sign(signer, alg, providerToken)
230+
cicToken, err := cic.Sign(signer, alg, idToken)
239231
if err != nil {
240232
return nil, fmt.Errorf("error creating cic token: %w", err)
241233
}
242234

243235
// Combine our ID token and signature over the cic to create our PK Token
244-
pkt, err := pktoken.New(providerToken, cicToken)
236+
pkt, err := pktoken.New(idToken, cicToken)
245237
if err != nil {
246238
return nil, fmt.Errorf("error creating PK Token: %w", err)
247239
}

providers/op.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ type RefreshableOpenIdProvider interface {
5757
// Interface for an OpenIdProvider that supports OAuth2 client credentials flow.
5858
type ClientCredentialsOpenIdProvider interface {
5959
OpenIdProvider
60-
RequestClientCredentialsTokens(ctx context.Context, scopes []string) (*simpleoidc.Tokens, error)
6160
}
6261

6362
// Interface for an OpenIdProvider that supports key binding of the ID Token

providers/standard_provider.go

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -409,21 +409,18 @@ func (s *StandardOp) RequestTokens(ctx context.Context, cic *clientinstance.Clai
409409
return nil, err
410410
}
411411

412-
providerToken := tokens.IDToken
413-
if s.ClientCredentialsFlow && len(providerToken) == 0 {
414-
providerToken = tokens.AccessToken
415-
}
412+
idToken := tokens.IDToken
416413

417414
if s.GQSign {
418-
if len(providerToken) == 0 {
419-
return nil, fmt.Errorf("cannot apply GQ signature: missing provider token")
415+
if len(idToken) == 0 {
416+
return nil, fmt.Errorf("cannot apply GQ signature: missing id token")
420417
}
421418

422419
var gqToken []byte
423420
if s.ClientCredentialsFlow {
424-
gqToken, err = CreateGQBoundToken(ctx, providerToken, s, string(cicHash))
421+
gqToken, err = CreateGQBoundToken(ctx, idToken, s, string(cicHash))
425422
} else {
426-
gqToken, err = CreateGQToken(ctx, providerToken, s)
423+
gqToken, err = CreateGQToken(ctx, idToken, s)
427424
}
428425
if err != nil {
429426
return nil, err
@@ -434,7 +431,9 @@ func (s *StandardOp) RequestTokens(ctx context.Context, cic *clientinstance.Clai
434431
return tokens, nil
435432
}
436433

437-
func (s *StandardOp) RequestClientCredentialsTokens(ctx context.Context, scopes []string) (*simpleoidc.Tokens, error) {
434+
func (s *StandardOp) clientCredentialsRequestTokens(ctx context.Context, _ string) (*simpleoidc.Tokens, error) {
435+
scopes := s.Scopes
436+
438437
if s.ClientSecret == "" {
439438
return nil, fmt.Errorf("client credentials flow requires a client secret")
440439
}
@@ -495,7 +494,7 @@ func (s *StandardOp) RequestClientCredentialsTokens(ctx context.Context, scopes
495494
return nil, fmt.Errorf("failed to decode token response: %w", err)
496495
}
497496

498-
if tokenResponse.AccessToken == "" && tokenResponse.IDToken == "" {
497+
if tokenResponse.IDToken == "" {
499498
return nil, fmt.Errorf("token endpoint response missing access_token and id_token")
500499
}
501500

@@ -506,10 +505,6 @@ func (s *StandardOp) RequestClientCredentialsTokens(ctx context.Context, scopes
506505
}, nil
507506
}
508507

509-
func (s *StandardOp) clientCredentialsRequestTokens(ctx context.Context, _ string) (*simpleoidc.Tokens, error) {
510-
return s.RequestClientCredentialsTokens(ctx, s.Scopes)
511-
}
512-
513508
func (s *StandardOp) deviceFlowRequestTokens(ctx context.Context, cicHash string) (*simpleoidc.Tokens, error) {
514509
cookieHandler, err := configCookieHandler()
515510
if err != nil {

0 commit comments

Comments
 (0)