|
7 | 7 | using System.Threading;
|
8 | 8 | using System.Threading.Tasks;
|
9 | 9 | using Microsoft.Identity.Client;
|
| 10 | +using Microsoft.Identity.Client.Extensibility; |
10 | 11 |
|
11 | 12 | namespace Azure.Identity
|
12 | 13 | {
|
13 | 14 | internal class MsalConfidentialClient : MsalClientBase<IConfidentialClientApplication>
|
14 | 15 | {
|
| 16 | + private const string s_instanceMetadata = "{\"tenant_discovery_endpoint\":\"https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration\",\"api-version\":\"1.1\",\"metadata\":[{\"preferred_network\":\"login.microsoftonline.com\",\"preferred_cache\":\"login.windows.net\",\"aliases\":[\"login.microsoftonline.com\",\"login.windows.net\",\"login.microsoft.com\",\"sts.windows.net\"]}]}"; |
15 | 17 | internal readonly string _clientSecret;
|
16 | 18 | internal readonly bool _includeX5CClaimHeader;
|
17 | 19 | internal readonly IX509Certificate2Provider _certificateProvider;
|
18 | 20 | private readonly Func<string> _assertionCallback;
|
19 | 21 | private readonly Func<CancellationToken, Task<string>> _asyncAssertionCallback;
|
| 22 | + private readonly Func<AppTokenProviderParameters, Task<AppTokenProviderResult>> _appTokenProviderCallback; |
20 | 23 |
|
21 | 24 | internal string RedirectUrl { get; }
|
22 | 25 |
|
@@ -52,15 +55,32 @@ public MsalConfidentialClient(CredentialPipeline pipeline, string tenantId, stri
|
52 | 55 | _asyncAssertionCallback = assertionCallback;
|
53 | 56 | }
|
54 | 57 |
|
| 58 | + public MsalConfidentialClient(CredentialPipeline pipeline, string tenantId, string clientId, Func<AppTokenProviderParameters, Task<AppTokenProviderResult>> appTokenProviderCallback, TokenCredentialOptions options) |
| 59 | + : base(pipeline, tenantId, clientId, options) |
| 60 | + { |
| 61 | + _appTokenProviderCallback = appTokenProviderCallback; |
| 62 | + } |
| 63 | + |
55 | 64 | internal string RegionalAuthority { get; } = EnvironmentVariables.AzureRegionalAuthorityName;
|
56 | 65 |
|
57 | 66 | protected override async ValueTask<IConfidentialClientApplication> CreateClientAsync(bool async, CancellationToken cancellationToken)
|
58 | 67 | {
|
59 | 68 | ConfidentialClientApplicationBuilder confClientBuilder = ConfidentialClientApplicationBuilder.Create(ClientId)
|
60 |
| - .WithAuthority(Pipeline.AuthorityHost.AbsoluteUri, TenantId) |
61 | 69 | .WithHttpClientFactory(new HttpPipelineClientFactory(Pipeline.HttpPipeline))
|
62 | 70 | .WithLogging(LogMsal, enablePiiLogging: IsPiiLoggingEnabled);
|
63 | 71 |
|
| 72 | + //special case for using appTokenProviderCallback, authority validation and instance metadata discovery should be disabled since we're not calling the STS |
| 73 | + if (_appTokenProviderCallback != null) |
| 74 | + { |
| 75 | + confClientBuilder.WithAppTokenProvider(_appTokenProviderCallback) |
| 76 | + .WithAuthority(Pipeline.AuthorityHost.AbsoluteUri, TenantId, false) |
| 77 | + .WithInstanceDiscoveryMetadata(s_instanceMetadata); |
| 78 | + } |
| 79 | + else |
| 80 | + { |
| 81 | + confClientBuilder.WithAuthority(Pipeline.AuthorityHost.AbsoluteUri, TenantId); |
| 82 | + } |
| 83 | + |
64 | 84 | if (_clientSecret != null)
|
65 | 85 | {
|
66 | 86 | confClientBuilder.WithClientSecret(_clientSecret);
|
|
0 commit comments