-
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 all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -506,81 +506,7 @@ private static async Task<AccessToken> GetTokenAsync(TokenCredentialKey tokenCre | |
|
|
||
| return await tokenCredentialInstance._tokenCredential.GetTokenAsync(tokenRequestContext, cancellationToken); | ||
| } | ||
|
|
||
| private static string GetAccountPwCacheKey(SqlAuthenticationParameters parameters) | ||
| { | ||
| return parameters.Authority + "+" + parameters.UserId; | ||
| } | ||
|
|
||
| private static byte[] GetHash(string input) | ||
| { | ||
| byte[] unhashedBytes = Encoding.Unicode.GetBytes(input); | ||
| SHA256 sha256 = SHA256.Create(); | ||
| byte[] hashedBytes = sha256.ComputeHash(unhashedBytes); | ||
| return hashedBytes; | ||
| } | ||
|
|
||
| private static bool AreEqual(byte[] a1, byte[] a2) | ||
| { | ||
| if (ReferenceEquals(a1, a2)) | ||
| { | ||
| return true; | ||
| } | ||
| else if (a1 is null || a2 is null) | ||
| { | ||
| return false; | ||
| } | ||
| else if (a1.Length != a2.Length) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| return a1.AsSpan().SequenceEqual(a2.AsSpan()); | ||
| } | ||
|
|
||
| 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)) | ||
|
|
@@ -634,6 +560,65 @@ private static TokenCredentialData CreateTokenCredentialInstance(TokenCredential | |
| throw new ArgumentException(nameof(ActiveDirectoryAuthenticationProvider)); | ||
| } | ||
|
|
||
| private static string GetAccountPwCacheKey(SqlAuthenticationParameters parameters) | ||
| { | ||
| return parameters.Authority + "+" + parameters.UserId; | ||
benrr101 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| private static byte[] GetHash(string input) | ||
| { | ||
| byte[] unhashedBytes = Encoding.Unicode.GetBytes(input); | ||
| SHA256 sha256 = SHA256.Create(); | ||
| byte[] hashedBytes = sha256.ComputeHash(unhashedBytes); | ||
| return hashedBytes; | ||
benrr101 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| private static bool AreEqual(byte[] a1, byte[] a2) | ||
benrr101 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| if (ReferenceEquals(a1, a2)) | ||
| { | ||
| return true; | ||
| } | ||
| else if (a1 is null || a2 is null) | ||
| { | ||
| return false; | ||
| } | ||
| else if (a1.Length != a2.Length) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| return a1.AsSpan().SequenceEqual(a2.AsSpan()); | ||
| } | ||
|
|
||
| private IPublicClientApplication CreateClientAppInstance(PublicClientAppKey publicClientAppKey) | ||
| { | ||
| PublicClientApplicationBuilder builder = PublicClientApplicationBuilder | ||
| .CreateWithApplicationOptions(new PublicClientApplicationOptions | ||
|
||
| { | ||
| 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) | ||
| { | ||
| builder = builder.WithParentActivityOrWindow(_iWin32WindowFunc); | ||
| } | ||
| #endif | ||
| #if NETSTANDARD | ||
| if (_parentActivityOrWindowFunc is not null) | ||
| { | ||
| builder = builder.WithParentActivityOrWindow(_parentActivityOrWindowFunc); | ||
| } | ||
| #endif | ||
|
|
||
| return builder.Build(); | ||
| } | ||
|
|
||
| internal class PublicClientAppKey | ||
| { | ||
| public readonly string _authority; | ||
|
|
||
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 🤦♂️