Skip to content

Commit 78dadc9

Browse files
authored
Port forward the 1.12.1 hotfix (Azure#46346)
1 parent 654eebc commit 78dadc9

26 files changed

+113
-64
lines changed

eng/Packages.Data.props

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,9 @@
153153
<!-- Other approved packages -->
154154
<PackageReference Update="Microsoft.Azure.Amqp" Version="2.6.7" />
155155
<PackageReference Update="Microsoft.Azure.WebPubSub.Common" Version="1.4.0" />
156-
<PackageReference Update="Microsoft.Identity.Client" Version="4.62.0" />
157-
<PackageReference Update="Microsoft.Identity.Client.Extensions.Msal" Version="4.62.0" />
158-
<!--
159-
TODO: This package needs to be released as GA and arch-board approved before taking a dependency in any stable SDK library.
160-
Currently, it is referenced by Azure.Identity.Broker which is still in beta
161-
-->
162-
<PackageReference Update="Microsoft.Identity.Client.Broker" Version="4.62.0" />
156+
<PackageReference Update="Microsoft.Identity.Client" Version="4.65.0" />
157+
<PackageReference Update="Microsoft.Identity.Client.Extensions.Msal" Version="4.65.0" />
158+
<PackageReference Update="Microsoft.Identity.Client.Broker" Version="4.65.0" />
163159

164160
<!-- TODO: Make sure this package is arch-board approved -->
165161
<PackageReference Update="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="6.35.0" />

sdk/identity/Azure.Identity/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
### Bugs Fixed
1010

1111
- Fixed the request sent in `AzurePipelinesCredential` so it doesn't result in a redirect response when an invalid system access token is provided.
12+
- Updated to version 4.65.0 of Microsoft.Identity.Client to address a bug preventing the use of alternate authority types such as dStS ([4927](https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/issues/4927)) .
1213

1314
### Other Changes
1415

sdk/identity/Azure.Identity/src/MsalClientBase.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,20 @@ await _clientWithCaeAsyncLock.GetLockOrValueAsync(true, default).ConfigureAwait(
108108

109109
return asyncLock.HasValue ? asyncLock.Value.Cache : null;
110110
}
111+
112+
public UriBuilder BuildTenantIdWithAuthorityHost(string tenantId)
113+
{
114+
UriBuilder uriBuilder = new(AuthorityHost);
115+
if (uriBuilder.Path.EndsWith("/"))
116+
{
117+
uriBuilder.Path += tenantId;
118+
}
119+
else
120+
{
121+
uriBuilder.Path = uriBuilder.Path + "/" + tenantId;
122+
}
123+
124+
return uriBuilder;
125+
}
111126
}
112127
}

sdk/identity/Azure.Identity/src/MsalConfidentialClient.cs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,7 @@ public virtual async ValueTask<AuthenticationResult> AcquireTokenForClientCoreAs
169169

170170
if (!string.IsNullOrEmpty(tenantId))
171171
{
172-
UriBuilder uriBuilder = new UriBuilder(AuthorityHost)
173-
{
174-
Path = tenantId
175-
};
172+
UriBuilder uriBuilder = BuildTenantIdWithAuthorityHost(tenantId);
176173
builder.WithTenantIdFromAuthority(uriBuilder.Uri);
177174
}
178175
if (!string.IsNullOrEmpty(claims))
@@ -214,10 +211,7 @@ public virtual async ValueTask<AuthenticationResult> AcquireTokenSilentCoreAsync
214211
var builder = client.AcquireTokenSilent(scopes, account);
215212
if (!string.IsNullOrEmpty(tenantId))
216213
{
217-
UriBuilder uriBuilder = new UriBuilder(AuthorityHost)
218-
{
219-
Path = tenantId
220-
};
214+
UriBuilder uriBuilder = BuildTenantIdWithAuthorityHost(tenantId);
221215
builder.WithTenantIdFromAuthority(uriBuilder.Uri);
222216
}
223217
if (!string.IsNullOrEmpty(claims))
@@ -260,10 +254,7 @@ public virtual async ValueTask<AuthenticationResult> AcquireTokenByAuthorization
260254

261255
if (!string.IsNullOrEmpty(tenantId))
262256
{
263-
UriBuilder uriBuilder = new UriBuilder(AuthorityHost)
264-
{
265-
Path = tenantId
266-
};
257+
UriBuilder uriBuilder = BuildTenantIdWithAuthorityHost(tenantId);
267258
builder.WithTenantIdFromAuthority(uriBuilder.Uri);
268259
}
269260
if (!string.IsNullOrEmpty(claims))
@@ -306,10 +297,7 @@ public virtual async ValueTask<AuthenticationResult> AcquireTokenOnBehalfOfCoreA
306297

307298
if (!string.IsNullOrEmpty(tenantId))
308299
{
309-
UriBuilder uriBuilder = new UriBuilder(AuthorityHost)
310-
{
311-
Path = tenantId
312-
};
300+
UriBuilder uriBuilder = BuildTenantIdWithAuthorityHost(tenantId);
313301
builder.WithTenantIdFromAuthority(uriBuilder.Uri);
314302
}
315303
if (!string.IsNullOrEmpty(claims))

sdk/identity/Azure.Identity/src/MsalPublicClient.cs

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,9 @@ protected virtual ValueTask<IPublicClientApplication> CreateClientCoreAsync(bool
4040
string[] clientCapabilities =
4141
enableCae ? cp1Capabilities : Array.Empty<string>();
4242

43-
var authorityUri = new UriBuilder(AuthorityHost.Scheme, AuthorityHost.Host, AuthorityHost.Port, TenantId ?? Constants.OrganizationsTenantId).Uri;
44-
4543
PublicClientApplicationBuilder pubAppBuilder = PublicClientApplicationBuilder
4644
.Create(ClientId)
47-
.WithAuthority(authorityUri)
45+
.WithAuthority(AuthorityHost.AbsoluteUri, TenantId ?? Constants.OrganizationsTenantId, false)
4846
.WithHttpClientFactory(new HttpPipelineClientFactory(Pipeline.HttpPipeline))
4947
.WithLogging(AzureIdentityEventSource.Singleton, enablePiiLogging: IsSupportLoggingEnabled);
5048

@@ -124,10 +122,7 @@ protected virtual async ValueTask<AuthenticationResult> AcquireTokenSilentCoreAs
124122
}
125123
if (tenantId != null)
126124
{
127-
UriBuilder uriBuilder = new UriBuilder(AuthorityHost)
128-
{
129-
Path = TenantId ?? tenantId
130-
};
125+
UriBuilder uriBuilder = BuildTenantIdWithAuthorityHost(tenantId);
131126
builder.WithTenantIdFromAuthority(uriBuilder.Uri);
132127
}
133128

@@ -183,10 +178,7 @@ protected virtual async ValueTask<AuthenticationResult> AcquireTokenSilentCoreAs
183178

184179
if (tenantId != null || record.TenantId != null)
185180
{
186-
UriBuilder uriBuilder = new UriBuilder(AuthorityHost)
187-
{
188-
Path = tenantId ?? record.TenantId
189-
};
181+
UriBuilder uriBuilder = BuildTenantIdWithAuthorityHost(tenantId ?? record.TenantId);
190182
builder.WithTenantIdFromAuthority(uriBuilder.Uri);
191183
}
192184

@@ -288,10 +280,7 @@ protected virtual async ValueTask<AuthenticationResult> AcquireTokenInteractiveC
288280
}
289281
if (tenantId != null)
290282
{
291-
UriBuilder uriBuilder = new UriBuilder(AuthorityHost)
292-
{
293-
Path = tenantId
294-
};
283+
UriBuilder uriBuilder = BuildTenantIdWithAuthorityHost(tenantId);
295284
builder.WithTenantIdFromAuthority(uriBuilder.Uri);
296285
}
297286
if (browserOptions != null)
@@ -333,10 +322,7 @@ protected virtual async ValueTask<AuthenticationResult> AcquireTokenByUsernamePa
333322
}
334323
if (!string.IsNullOrEmpty(tenantId))
335324
{
336-
UriBuilder uriBuilder = new UriBuilder(AuthorityHost)
337-
{
338-
Path = tenantId
339-
};
325+
UriBuilder uriBuilder = BuildTenantIdWithAuthorityHost(tenantId);
340326
builder.WithTenantIdFromAuthority(uriBuilder.Uri);
341327
}
342328
return await builder.ExecuteAsync(async, cancellationToken)
@@ -359,6 +345,11 @@ protected virtual async ValueTask<AuthenticationResult> AcquireTokenWithDeviceCo
359345
{
360346
builder.WithClaims(claims);
361347
}
348+
if (!string.IsNullOrEmpty(TenantId))
349+
{
350+
UriBuilder uriBuilder = BuildTenantIdWithAuthorityHost(TenantId);
351+
builder.WithTenantIdFromAuthority(uriBuilder.Uri);
352+
}
362353

363354
return await builder.ExecuteAsync(async, cancellationToken)
364355
.ConfigureAwait(false);
@@ -383,10 +374,7 @@ protected virtual async ValueTask<AuthenticationResult> AcquireTokenByRefreshTok
383374

384375
if (!string.IsNullOrEmpty(TenantId))
385376
{
386-
UriBuilder uriBuilder = new UriBuilder(AuthorityHost)
387-
{
388-
Path = tenant
389-
};
377+
UriBuilder uriBuilder = BuildTenantIdWithAuthorityHost(TenantId);
390378
builder.WithTenantIdFromAuthority(uriBuilder.Uri);
391379
}
392380

sdk/identity/Azure.Identity/tests/AuthorizationCodeCredentialTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public override TokenCredential GetTokenCredential(CommonCredentialTestConfig co
3434
AdditionallyAllowedTenants = config.AdditionallyAllowedTenants,
3535
IsUnsafeSupportLoggingEnabled = config.IsUnsafeSupportLoggingEnabled,
3636
RedirectUri = config.RedirectUri,
37+
AuthorityHost = config.AuthorityHost,
3738
};
3839
if (config.Transport != null)
3940
{

sdk/identity/Azure.Identity/tests/AzureCliCredentialTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public override TokenCredential GetTokenCredential(CommonCredentialTestConfig co
3535
AdditionallyAllowedTenants = config.AdditionallyAllowedTenants,
3636
TenantId = config.TenantId,
3737
IsUnsafeSupportLoggingEnabled = config.IsUnsafeSupportLoggingEnabled,
38+
AuthorityHost = config.AuthorityHost,
3839
};
3940
var (_, _, processOutput) = CredentialTestHelpers.CreateTokenForAzureCli();
4041
var testProcess = new TestProcess { Output = processOutput };

sdk/identity/Azure.Identity/tests/AzureDeveloperCliCredentialTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public override TokenCredential GetTokenCredential(CommonCredentialTestConfig co
3434
AdditionallyAllowedTenants = config.AdditionallyAllowedTenants,
3535
TenantId = config.TenantId,
3636
IsUnsafeSupportLoggingEnabled = config.IsUnsafeSupportLoggingEnabled,
37+
AuthorityHost = config.AuthorityHost,
3738
};
3839
var (_, _, processOutput) = CredentialTestHelpers.CreateTokenForAzureDeveloperCli();
3940
var testProcess = new TestProcess { Output = processOutput };

sdk/identity/Azure.Identity/tests/AzurePipelinesCredentialTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public override TokenCredential GetTokenCredential(CommonCredentialTestConfig co
4444
IsUnsafeSupportLoggingEnabled = config.IsUnsafeSupportLoggingEnabled,
4545
MsalClient = config.MockConfidentialMsalClient,
4646
OidcRequestUri = "https://dev.azure.com/myorg/myproject/_apis/serviceendpoint/endpoints?api-version=2.2.2",
47+
AuthorityHost = config.AuthorityHost,
4748
};
4849
if (config.Transport != null)
4950
{

sdk/identity/Azure.Identity/tests/AzurePowerShellCredentialsTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public override TokenCredential GetTokenCredential(CommonCredentialTestConfig co
4242
AdditionallyAllowedTenants = config.AdditionallyAllowedTenants,
4343
TenantId = config.TenantId,
4444
IsUnsafeSupportLoggingEnabled = config.IsUnsafeSupportLoggingEnabled,
45+
AuthorityHost = config.AuthorityHost,
4546
};
4647
var (_, _, processOutput) = CredentialTestHelpers.CreateTokenForAzurePowerShell(TimeSpan.FromSeconds(30));
4748
var testProcess = new TestProcess { Output = processOutput };

0 commit comments

Comments
 (0)