Skip to content

Commit 9020972

Browse files
authored
azcore: Remove CAE support (#20497)
1 parent 1cd56ad commit 9020972

File tree

4 files changed

+9
-54
lines changed

4 files changed

+9
-54
lines changed

sdk/azcore/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
* Added `ShouldRetry` to `policy.RetryOptions` for finer-grained control over when to retry.
77

88
### Breaking Changes
9+
> These changes affect only code written against a beta version such as v1.5.0-beta.1
10+
* Removed `Claims` and `TenantID` fields from `policy.TokenRequestOptions`
11+
* Removed CAE support for ARM clients
912

1013
### Bugs Fixed
1114
* Added non-conformant LRO terminal states `Cancelled` and `Completed`.

sdk/azcore/arm/runtime/policy_bearer_token.go

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package runtime
55

66
import (
77
"context"
8-
"encoding/base64"
98
"fmt"
109
"net/http"
1110
"strings"
@@ -64,28 +63,11 @@ func NewBearerTokenPolicy(cred azcore.TokenCredential, opts *armpolicy.BearerTok
6463
p.scopes = make([]string, len(opts.Scopes))
6564
copy(p.scopes, opts.Scopes)
6665
p.btp = azruntime.NewBearerTokenPolicy(cred, opts.Scopes, &azpolicy.BearerTokenOptions{
67-
AuthorizationHandler: azpolicy.AuthorizationHandler{
68-
OnChallenge: p.onChallenge,
69-
OnRequest: p.onRequest,
70-
},
66+
AuthorizationHandler: azpolicy.AuthorizationHandler{OnRequest: p.onRequest},
7167
})
7268
return p
7369
}
7470

75-
func (b *BearerTokenPolicy) onChallenge(req *azpolicy.Request, res *http.Response, authNZ func(azpolicy.TokenRequestOptions) error) error {
76-
challenge := res.Header.Get(shared.HeaderWWWAuthenticate)
77-
claims, err := parseChallenge(challenge)
78-
if err != nil {
79-
// the challenge contains claims we can't parse
80-
return err
81-
} else if claims != "" {
82-
// request a new token having the specified claims, send the request again
83-
return authNZ(azpolicy.TokenRequestOptions{Claims: claims, Scopes: b.scopes})
84-
}
85-
// auth challenge didn't include claims, so this is a simple authorization failure
86-
return azruntime.NewResponseError(res)
87-
}
88-
8971
// onRequest authorizes requests with one or more bearer tokens
9072
func (b *BearerTokenPolicy) onRequest(req *azpolicy.Request, authNZ func(azpolicy.TokenRequestOptions) error) error {
9173
// authorize the request with a token for the primary tenant
@@ -115,31 +97,3 @@ func (b *BearerTokenPolicy) onRequest(req *azpolicy.Request, authNZ func(azpolic
11597
func (b *BearerTokenPolicy) Do(req *azpolicy.Request) (*http.Response, error) {
11698
return b.btp.Do(req)
11799
}
118-
119-
// parseChallenge parses claims from an authentication challenge issued by ARM so a client can request a token
120-
// that will satisfy conditional access policies. It returns a non-nil error when the given value contains
121-
// claims it can't parse. If the value contains no claims, it returns an empty string and a nil error.
122-
func parseChallenge(wwwAuthenticate string) (string, error) {
123-
claims := ""
124-
var err error
125-
for _, param := range strings.Split(wwwAuthenticate, ",") {
126-
if _, after, found := strings.Cut(param, "claims="); found {
127-
if claims != "" {
128-
// The header contains multiple challenges, at least two of which specify claims. The specs allow this
129-
// but it's unclear what a client should do in this case and there's as yet no concrete example of it.
130-
err = fmt.Errorf("found multiple claims challenges in %q", wwwAuthenticate)
131-
break
132-
}
133-
// trim stuff that would get an error from RawURLEncoding; claims may or may not be padded
134-
claims = strings.Trim(after, `\"=`)
135-
// we don't return this error because it's something unhelpful like "illegal base64 data at input byte 42"
136-
if b, decErr := base64.RawURLEncoding.DecodeString(claims); decErr == nil {
137-
claims = string(b)
138-
} else {
139-
err = fmt.Errorf("failed to parse claims from %q", wwwAuthenticate)
140-
break
141-
}
142-
}
143-
}
144-
return claims, err
145-
}

sdk/azcore/arm/runtime/policy_bearer_token_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ func TestAuxiliaryTenants(t *testing.T) {
203203
}
204204

205205
func TestBearerTokenPolicyChallengeParsing(t *testing.T) {
206+
t.Skip("unskip this test after adding back CAE support")
206207
for _, test := range []struct {
207208
challenge, desc, expectedClaims string
208209
err error
@@ -261,9 +262,10 @@ func TestBearerTokenPolicyChallengeParsing(t *testing.T) {
261262
cred := mockCredential{
262263
getTokenImpl: func(ctx context.Context, actual azpolicy.TokenRequestOptions) (azcore.AccessToken, error) {
263264
calls += 1
264-
if calls == 2 && test.expectedClaims != "" {
265-
require.Equal(t, test.expectedClaims, actual.Claims)
266-
}
265+
// TODO: uncomment after restoring TokenRequestOptions.Claims
266+
// if calls == 2 && test.expectedClaims != "" {
267+
// require.Equal(t, test.expectedClaims, actual.Claims)
268+
// }
267269
return azcore.AccessToken{Token: "...", ExpiresOn: time.Now().Add(time.Hour).UTC()}, nil
268270
},
269271
}

sdk/azcore/internal/exported/exported.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,6 @@ type AccessToken struct {
7171
// TokenRequestOptions contain specific parameter that may be used by credentials types when attempting to get a token.
7272
// Exported as policy.TokenRequestOptions.
7373
type TokenRequestOptions struct {
74-
// Claims are any additional claims required for the token to satisfy a conditional access policy, such as a
75-
// service may return in a claims challenge following an authorization failure. If a service returned the
76-
// claims value base64 encoded, it must be decoded before setting this field.
77-
Claims string
7874
// Scopes contains the list of permission scopes required for the token.
7975
Scopes []string
8076

0 commit comments

Comments
 (0)