-
Notifications
You must be signed in to change notification settings - Fork 317
5.1 | APIScan | MSAL WithClientName
#3358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -540,98 +540,30 @@ private static bool AreEqual(byte[] a1, byte[] a2) | |
|
|
||
| private IPublicClientApplication CreateClientAppInstance(PublicClientAppKey publicClientAppKey) | ||
| { | ||
| IPublicClientApplication publicClientApplication; | ||
|
|
||
| #if NETSTANDARD | ||
| if (_parentActivityOrWindowFunc != null) | ||
| { | ||
| publicClientApplication = PublicClientApplicationBuilder.Create(publicClientAppKey._applicationClientId) | ||
| .WithAuthority(publicClientAppKey._authority) | ||
| .WithClientName(Common.DbConnectionStringDefaults.ApplicationName) | ||
| .WithClientVersion(Common.ADP.GetAssemblyVersion().ToString()) | ||
| .WithRedirectUri(publicClientAppKey._redirectUri) | ||
| .WithParentActivityOrWindow(_parentActivityOrWindowFunc) | ||
| .Build(); | ||
| } | ||
| #endif | ||
| #if NETFRAMEWORK | ||
| if (_iWin32WindowFunc != null) | ||
| { | ||
| publicClientApplication = PublicClientApplicationBuilder.Create(publicClientAppKey._applicationClientId) | ||
| .WithAuthority(publicClientAppKey._authority) | ||
| .WithClientName(Common.DbConnectionStringDefaults.ApplicationName) | ||
| .WithClientVersion(Common.ADP.GetAssemblyVersion().ToString()) | ||
| .WithRedirectUri(publicClientAppKey._redirectUri) | ||
| .WithParentActivityOrWindow(_iWin32WindowFunc) | ||
| .Build(); | ||
| } | ||
| #endif | ||
| #if !NETCOREAPP | ||
| else | ||
| #endif | ||
| { | ||
| publicClientApplication = PublicClientApplicationBuilder.Create(publicClientAppKey._applicationClientId) | ||
| .WithAuthority(publicClientAppKey._authority) | ||
| .WithClientName(Common.DbConnectionStringDefaults.ApplicationName) | ||
| .WithClientVersion(Common.ADP.GetAssemblyVersion().ToString()) | ||
| .WithRedirectUri(publicClientAppKey._redirectUri) | ||
| .Build(); | ||
| } | ||
|
|
||
| return publicClientApplication; | ||
| } | ||
|
|
||
| private static TokenCredentialData CreateTokenCredentialInstance(TokenCredentialKey tokenCredentialKey, string secret) | ||
| { | ||
| if (tokenCredentialKey._tokenCredentialType == typeof(DefaultAzureCredential)) | ||
| { | ||
| DefaultAzureCredentialOptions defaultAzureCredentialOptions = new() | ||
| { | ||
| AuthorityHost = new Uri(tokenCredentialKey._authority), | ||
| SharedTokenCacheTenantId = tokenCredentialKey._audience, | ||
| VisualStudioCodeTenantId = tokenCredentialKey._audience, | ||
| VisualStudioTenantId = tokenCredentialKey._audience, | ||
| ExcludeInteractiveBrowserCredential = true // Force disabled, even though it's disabled by default to respect driver specifications. | ||
| }; | ||
|
|
||
| // Optionally set clientId when available | ||
| if (tokenCredentialKey._clientId is not null) | ||
| PublicClientApplicationBuilder builder = PublicClientApplicationBuilder | ||
| .CreateWithApplicationOptions(new PublicClientApplicationOptions | ||
|
||
| { | ||
| defaultAzureCredentialOptions.ManagedIdentityClientId = tokenCredentialKey._clientId; | ||
| defaultAzureCredentialOptions.SharedTokenCacheUsername = tokenCredentialKey._clientId; | ||
| defaultAzureCredentialOptions.WorkloadIdentityClientId = tokenCredentialKey._clientId; | ||
| } | ||
|
|
||
| return new TokenCredentialData(new DefaultAzureCredential(defaultAzureCredentialOptions), GetHash(secret)); | ||
| } | ||
|
|
||
| TokenCredentialOptions tokenCredentialOptions = new() { AuthorityHost = new Uri(tokenCredentialKey._authority) }; | ||
|
|
||
| if (tokenCredentialKey._tokenCredentialType == typeof(ManagedIdentityCredential)) | ||
| { | ||
| return new TokenCredentialData(new ManagedIdentityCredential(tokenCredentialKey._clientId, tokenCredentialOptions), GetHash(secret)); | ||
| } | ||
| else if (tokenCredentialKey._tokenCredentialType == typeof(ClientSecretCredential)) | ||
| ClientId = publicClientAppKey._applicationClientId, | ||
| ClientName = Common.DbConnectionStringDefaults.ApplicationName, | ||
| ClientVersion = Common.ADP.GetAssemblyVersion().ToString(), | ||
| RedirectUri = publicClientAppKey._redirectUri, | ||
| }) | ||
| .WithAuthority(publicClientAppKey._authority); | ||
|
|
||
| #if NETFRAMEWORK | ||
| if (_iWin32WindowFunc is not null) | ||
| { | ||
| return new TokenCredentialData(new ClientSecretCredential(tokenCredentialKey._audience, tokenCredentialKey._clientId, secret, tokenCredentialOptions), GetHash(secret)); | ||
| builder = builder.WithParentActivityOrWindow(_iWin32WindowFunc); | ||
| } | ||
| else if (tokenCredentialKey._tokenCredentialType == typeof(WorkloadIdentityCredential)) | ||
| #endif | ||
| #if NETSTANDARD | ||
| if (_parentActivityOrWindowFunc is not null) | ||
| { | ||
| // The WorkloadIdentityCredentialOptions object initialization populates its instance members | ||
| // from the environment variables AZURE_TENANT_ID, AZURE_CLIENT_ID, AZURE_FEDERATED_TOKEN_FILE, | ||
| // and AZURE_ADDITIONALLY_ALLOWED_TENANTS. AZURE_CLIENT_ID may be overridden by the User Id. | ||
| WorkloadIdentityCredentialOptions options = new() { AuthorityHost = new Uri(tokenCredentialKey._authority) }; | ||
|
|
||
| if (tokenCredentialKey._clientId is not null) | ||
| { | ||
| options.ClientId = tokenCredentialKey._clientId; | ||
| } | ||
|
|
||
| return new TokenCredentialData(new WorkloadIdentityCredential(options), GetHash(secret)); | ||
| builder = builder.WithParentActivityOrWindow(_parentActivityOrWindowFunc); | ||
| } | ||
| #endif | ||
|
|
||
| // This should never be reached, but if it is, throw an exception that will be noticed during development | ||
| throw new ArgumentException(nameof(ActiveDirectoryAuthenticationProvider)); | ||
| return builder.Build(); | ||
| } | ||
|
|
||
| internal class PublicClientAppKey | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, it was a mistake 🤦♂️