Skip to content

Commit e5c2817

Browse files
authored
Enable CAE by default in azidentity beta (#20928)
1 parent 6533d46 commit e5c2817

13 files changed

+27
-28
lines changed

sdk/azidentity/CHANGELOG.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
# Release History
22

3-
## 1.3.1 (Unreleased)
4-
5-
### Features Added
6-
7-
### Breaking Changes
8-
9-
### Bugs Fixed
3+
## 1.4.0-beta.1 (2023-06-06)
104

115
### Other Changes
6+
* Re-enabled CAE support as in v1.3.0-beta.3
127

138
## 1.3.0 (2023-05-09)
149

sdk/azidentity/azidentity.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ const (
4646

4747
var (
4848
// capability CP1 indicates the client application is capable of handling CAE claims challenges
49-
cp1 = []string{"CP1"}
50-
// CP1 is disabled until CAE support is added back
51-
disableCP1 = true
49+
cp1 = []string{"CP1"}
50+
disableCP1 = strings.ToLower(os.Getenv("AZURE_IDENTITY_DISABLE_CP1")) == "true"
5251
)
5352

5453
var getConfidentialClient = func(clientID, tenantID string, cred confidential.Credential, co *azcore.ClientOptions, additionalOpts ...confidential.Option) (confidentialClient, error) {

sdk/azidentity/azidentity_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,6 @@ func TestAdditionallyAllowedTenants(t *testing.T) {
560560
}
561561

562562
func TestClaims(t *testing.T) {
563-
t.Skip("unskip this test after adding back CAE support")
564563
realCP1 := disableCP1
565564
t.Cleanup(func() { disableCP1 = realCP1 })
566565
claim := `"test":"pass"`
@@ -650,10 +649,9 @@ func TestClaims(t *testing.T) {
650649
if _, err = cred.GetToken(context.Background(), policy.TokenRequestOptions{Scopes: []string{"A"}}); err != nil {
651650
t.Fatal(err)
652651
}
653-
// TODO: uncomment after restoring TokenRequestOptions.Claims
654-
// if _, err = cred.GetToken(context.Background(), policy.TokenRequestOptions{Claims: fmt.Sprintf("{%s}", claim), Scopes: []string{"B"}}); err != nil {
655-
// t.Fatal(err)
656-
// }
652+
if _, err = cred.GetToken(context.Background(), policy.TokenRequestOptions{Claims: fmt.Sprintf("{%s}", claim), Scopes: []string{"B"}}); err != nil {
653+
t.Fatal(err)
654+
}
657655
if reqs != 2 {
658656
t.Fatalf("expected %d token requests, got %d", 2, reqs)
659657
}

sdk/azidentity/client_assertion_credential.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ func (c *ClientAssertionCredential) GetToken(ctx context.Context, opts policy.To
7171
}
7272

7373
func (c *ClientAssertionCredential) silentAuth(ctx context.Context, opts policy.TokenRequestOptions) (azcore.AccessToken, error) {
74-
ar, err := c.client.AcquireTokenSilent(ctx, opts.Scopes, confidential.WithTenantID(opts.TenantID))
74+
ar, err := c.client.AcquireTokenSilent(ctx, opts.Scopes, confidential.WithClaims(opts.Claims), confidential.WithTenantID(opts.TenantID))
7575
return azcore.AccessToken{Token: ar.AccessToken, ExpiresOn: ar.ExpiresOn.UTC()}, err
7676
}
7777

7878
func (c *ClientAssertionCredential) requestToken(ctx context.Context, opts policy.TokenRequestOptions) (azcore.AccessToken, error) {
79-
ar, err := c.client.AcquireTokenByCredential(ctx, opts.Scopes, confidential.WithTenantID(opts.TenantID))
79+
ar, err := c.client.AcquireTokenByCredential(ctx, opts.Scopes, confidential.WithClaims(opts.Claims), confidential.WithTenantID(opts.TenantID))
8080
return azcore.AccessToken{Token: ar.AccessToken, ExpiresOn: ar.ExpiresOn.UTC()}, err
8181
}
8282

sdk/azidentity/client_certificate_credential.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ func (c *ClientCertificateCredential) GetToken(ctx context.Context, opts policy.
7878
}
7979

8080
func (c *ClientCertificateCredential) silentAuth(ctx context.Context, opts policy.TokenRequestOptions) (azcore.AccessToken, error) {
81-
ar, err := c.client.AcquireTokenSilent(ctx, opts.Scopes, confidential.WithTenantID(opts.TenantID))
81+
ar, err := c.client.AcquireTokenSilent(ctx, opts.Scopes, confidential.WithClaims(opts.Claims), confidential.WithTenantID(opts.TenantID))
8282
return azcore.AccessToken{Token: ar.AccessToken, ExpiresOn: ar.ExpiresOn.UTC()}, err
8383
}
8484

8585
func (c *ClientCertificateCredential) requestToken(ctx context.Context, opts policy.TokenRequestOptions) (azcore.AccessToken, error) {
86-
ar, err := c.client.AcquireTokenByCredential(ctx, opts.Scopes, confidential.WithTenantID(opts.TenantID))
86+
ar, err := c.client.AcquireTokenByCredential(ctx, opts.Scopes, confidential.WithClaims(opts.Claims), confidential.WithTenantID(opts.TenantID))
8787
return azcore.AccessToken{Token: ar.AccessToken, ExpiresOn: ar.ExpiresOn.UTC()}, err
8888
}
8989

sdk/azidentity/client_secret_credential.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ func (c *ClientSecretCredential) GetToken(ctx context.Context, opts policy.Token
6363
}
6464

6565
func (c *ClientSecretCredential) silentAuth(ctx context.Context, opts policy.TokenRequestOptions) (azcore.AccessToken, error) {
66-
ar, err := c.client.AcquireTokenSilent(ctx, opts.Scopes, confidential.WithTenantID(opts.TenantID))
66+
ar, err := c.client.AcquireTokenSilent(ctx, opts.Scopes, confidential.WithClaims(opts.Claims), confidential.WithTenantID(opts.TenantID))
6767
return azcore.AccessToken{Token: ar.AccessToken, ExpiresOn: ar.ExpiresOn.UTC()}, err
6868
}
6969

7070
func (c *ClientSecretCredential) requestToken(ctx context.Context, opts policy.TokenRequestOptions) (azcore.AccessToken, error) {
71-
ar, err := c.client.AcquireTokenByCredential(ctx, opts.Scopes, confidential.WithTenantID(opts.TenantID))
71+
ar, err := c.client.AcquireTokenByCredential(ctx, opts.Scopes, confidential.WithClaims(opts.Claims), confidential.WithTenantID(opts.TenantID))
7272
return azcore.AccessToken{Token: ar.AccessToken, ExpiresOn: ar.ExpiresOn.UTC()}, err
7373
}
7474

sdk/azidentity/device_code_credential.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func (c *DeviceCodeCredential) GetToken(ctx context.Context, opts policy.TokenRe
105105
}
106106

107107
func (c *DeviceCodeCredential) requestToken(ctx context.Context, opts policy.TokenRequestOptions) (azcore.AccessToken, error) {
108-
dc, err := c.client.AcquireTokenByDeviceCode(ctx, opts.Scopes, public.WithTenantID(opts.TenantID))
108+
dc, err := c.client.AcquireTokenByDeviceCode(ctx, opts.Scopes, public.WithClaims(opts.Claims), public.WithTenantID(opts.TenantID))
109109
if err != nil {
110110
return azcore.AccessToken{}, err
111111
}
@@ -127,6 +127,7 @@ func (c *DeviceCodeCredential) requestToken(ctx context.Context, opts policy.Tok
127127

128128
func (c *DeviceCodeCredential) silentAuth(ctx context.Context, opts policy.TokenRequestOptions) (azcore.AccessToken, error) {
129129
ar, err := c.client.AcquireTokenSilent(ctx, opts.Scopes,
130+
public.WithClaims(opts.Claims),
130131
public.WithSilentAccount(c.account),
131132
public.WithTenantID(opts.TenantID),
132133
)

sdk/azidentity/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/Azure/azure-sdk-for-go/sdk/azidentity
33
go 1.18
44

55
require (
6-
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.6.0
6+
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.7.0-beta.1
77
github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0
88
github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0
99
github.com/golang-jwt/jwt/v4 v4.5.0

sdk/azidentity/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.6.0 h1:8kDqDngH+DmVBiCtIjCFTGa7MBnsIOkF9IccInFEbjk=
2-
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.6.0/go.mod h1:bjGvMhVMb+EEm3VRNQawDMUyMMjo+S5ewNjflkep/0Q=
1+
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.7.0-beta.1 h1:TpBJ3UP3Vx9OBk1nP/5FynUmQXPeIq2RXadb4gq8ZgU=
2+
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.7.0-beta.1/go.mod h1:bjGvMhVMb+EEm3VRNQawDMUyMMjo+S5ewNjflkep/0Q=
33
github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 h1:sXr+ck84g/ZlZUOZiNELInmMgOsuGwdjjVkEIde0OtY=
44
github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0/go.mod h1:okt5dMMTOFjX/aovMlrjvvXoPMBVSPzk9185BT0+eZM=
55
github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0 h1:OBhqkivkhkMqLPymWEppkm7vgPQY2XsHoEkaMQ0AdZY=

sdk/azidentity/interactive_browser_credential.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ func (c *InteractiveBrowserCredential) GetToken(ctx context.Context, opts policy
8585

8686
func (c *InteractiveBrowserCredential) requestToken(ctx context.Context, opts policy.TokenRequestOptions) (azcore.AccessToken, error) {
8787
ar, err := c.client.AcquireTokenInteractive(ctx, opts.Scopes,
88+
public.WithClaims(opts.Claims),
8889
public.WithLoginHint(c.options.LoginHint),
8990
public.WithRedirectURI(c.options.RedirectURL),
9091
public.WithTenantID(opts.TenantID),
@@ -97,6 +98,7 @@ func (c *InteractiveBrowserCredential) requestToken(ctx context.Context, opts po
9798

9899
func (c *InteractiveBrowserCredential) silentAuth(ctx context.Context, opts policy.TokenRequestOptions) (azcore.AccessToken, error) {
99100
ar, err := c.client.AcquireTokenSilent(ctx, opts.Scopes,
101+
public.WithClaims(opts.Claims),
100102
public.WithSilentAccount(c.account),
101103
public.WithTenantID(opts.TenantID),
102104
)

0 commit comments

Comments
 (0)