Skip to content

Commit

Permalink
pr changes
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyOHart committed Oct 22, 2024
1 parent 6e7f5fa commit 7e9056d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 36 deletions.
46 changes: 13 additions & 33 deletions apps/managedidentity/managedidentity.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,23 +241,19 @@ func (client Client) AcquireToken(ctx context.Context, resource string, options

// ignore cached access tokens when given claims
if o.claims == "" {
return handleCachedToken(ctx, fakeAuthParams)
}

// if o.claims == "" {
// if cacheManager == nil {
// return base.AuthResult{}, errors.New("cache instance is nil")
// }
// storageTokenResponse, err := cacheManager.Read(ctx, fakeAuthParams)
// if err != nil {
// return base.AuthResult{}, err
// }
// ar, err := base.AuthResultFromStorage(storageTokenResponse)
// if err == nil {
// ar.AccessToken, err = fakeAuthParams.AuthnScheme.FormatAccessToken(ar.AccessToken)
// return ar, err
// }
// }
if cacheManager == nil {
return base.AuthResult{}, errors.New("cache instance is nil")
}
storageTokenResponse, err := cacheManager.Read(ctx, fakeAuthParams)
if err != nil {
return base.AuthResult{}, err
}
ar, err := base.AuthResultFromStorage(storageTokenResponse)
if err == nil {
ar.AccessToken, err = fakeAuthParams.AuthnScheme.FormatAccessToken(ar.AccessToken)
return ar, err
}
}

switch client.source {
case AzureArc:
Expand Down Expand Up @@ -320,22 +316,6 @@ func createFakeAuthParams(client Client) (authority.AuthParams, error) {
return authority.NewAuthParams(client.miType.value(), fakeAuthInfo), nil
}

func handleCachedToken(ctx context.Context, fakeAuthParams authority.AuthParams) (base.AuthResult, error) {
if cacheManager == nil {
return base.AuthResult{}, errors.New("cache instance is nil")
}
storageTokenResponse, err := cacheManager.Read(ctx, fakeAuthParams)
if err != nil {
return base.AuthResult{}, err
}
ar, err := base.AuthResultFromStorage(storageTokenResponse)
if err == nil {
ar.AccessToken, err = fakeAuthParams.AuthnScheme.FormatAccessToken(ar.AccessToken)
return ar, err
}
return base.AuthResult{}, err
}

func authResultFromToken(authParams authority.AuthParams, token accesstokens.TokenResponse) (base.AuthResult, error) {
if cacheManager == nil {
return base.AuthResult{}, errors.New("cache instance is nil")
Expand Down
6 changes: 3 additions & 3 deletions apps/managedidentity/managedidentity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func TestIMDSAcquireTokenReturnsTokenSuccess(t *testing.T) {
t.Fatal(err)
}

result, err := client.AcquireToken(context.Background(), testCase.resource, WithClaims("claim"))
result, err := client.AcquireToken(context.Background(), testCase.resource)

if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -379,7 +379,7 @@ func TestAzureArcAcquireTokenReturnsTokenSuccess(t *testing.T) {
t.Fatal(err)
}

result, err := client.AcquireToken(context.Background(), testCase.resource, WithClaims("claim"))
result, err := client.AcquireToken(context.Background(), testCase.resource)

if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -485,7 +485,7 @@ func TestSystemAssignedReturnsAcquireTokenFailure(t *testing.T) {
if err != nil {
t.Fatal(err)
}
resp, err := client.AcquireToken(context.Background(), resource, WithClaims("claim"))
resp, err := client.AcquireToken(context.Background(), resource)
if err == nil {
t.Fatalf("should have encountered the error")
}
Expand Down

0 comments on commit 7e9056d

Please sign in to comment.