@@ -28,12 +28,12 @@ type acquiringResourceState struct {
28
28
tenant string
29
29
}
30
30
31
- // acquire acquires or updates the resource; only one
32
- // thread/goroutine at a time ever calls this function
33
- func acquire (state acquiringResourceState ) (newResource azcore.AccessToken , newExpiration time.Time , err error ) {
31
+ // acquireAuxToken acquires a token from an auxiliary tenant. Only one thread/goroutine at a time ever calls this function.
32
+ func acquireAuxToken (state acquiringResourceState ) (newResource azcore.AccessToken , newExpiration time.Time , err error ) {
34
33
tk , err := state .p .cred .GetToken (state .ctx , azpolicy.TokenRequestOptions {
35
- Scopes : state .p .scopes ,
36
- TenantID : state .tenant ,
34
+ EnableCAE : true ,
35
+ Scopes : state .p .scopes ,
36
+ TenantID : state .tenant ,
37
37
})
38
38
if err != nil {
39
39
return azcore.AccessToken {}, time.Time {}, err
@@ -59,7 +59,7 @@ func NewBearerTokenPolicy(cred azcore.TokenCredential, opts *armpolicy.BearerTok
59
59
p := & BearerTokenPolicy {cred : cred }
60
60
p .auxResources = make (map [string ]* temporal.Resource [azcore.AccessToken , acquiringResourceState ], len (opts .AuxiliaryTenants ))
61
61
for _ , t := range opts .AuxiliaryTenants {
62
- p .auxResources [t ] = temporal .NewResource (acquire )
62
+ p .auxResources [t ] = temporal .NewResource (acquireAuxToken )
63
63
}
64
64
p .scopes = make ([]string , len (opts .Scopes ))
65
65
copy (p .scopes , opts .Scopes )
@@ -80,7 +80,7 @@ func (b *BearerTokenPolicy) onChallenge(req *azpolicy.Request, res *http.Respons
80
80
return err
81
81
} else if claims != "" {
82
82
// request a new token having the specified claims, send the request again
83
- return authNZ (azpolicy.TokenRequestOptions {Claims : claims , Scopes : b .scopes })
83
+ return authNZ (azpolicy.TokenRequestOptions {Claims : claims , EnableCAE : true , Scopes : b .scopes })
84
84
}
85
85
// auth challenge didn't include claims, so this is a simple authorization failure
86
86
return azruntime .NewResponseError (res )
@@ -89,7 +89,7 @@ func (b *BearerTokenPolicy) onChallenge(req *azpolicy.Request, res *http.Respons
89
89
// onRequest authorizes requests with one or more bearer tokens
90
90
func (b * BearerTokenPolicy ) onRequest (req * azpolicy.Request , authNZ func (azpolicy.TokenRequestOptions ) error ) error {
91
91
// authorize the request with a token for the primary tenant
92
- err := authNZ (azpolicy.TokenRequestOptions {Scopes : b .scopes })
92
+ err := authNZ (azpolicy.TokenRequestOptions {EnableCAE : true , Scopes : b .scopes })
93
93
if err != nil || len (b .auxResources ) == 0 {
94
94
return err
95
95
}
0 commit comments