Skip to content

Commit

Permalink
Add WithAuthority to MSAL application level (#6671)
Browse files Browse the repository at this point in the history
  • Loading branch information
sw-joelmut authored Jul 13, 2023
1 parent 748aef5 commit 332d26c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ protected override Lazy<IAuthenticator> BuildIAuthenticator()
private Identity.Client.IConfidentialClientApplication CreateClientApplication(X509Certificate2 clientCertificate, string appId, HttpClient customHttpClient = null)
{
var clientBuilder = Identity.Client.ConfidentialClientApplicationBuilder.Create(appId)
.WithAuthority(new Uri(OAuthEndpoint), ValidateAuthority)
.WithCertificate(clientCertificate);

if (customHttpClient != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ protected override Lazy<IAuthenticator> BuildIAuthenticator()
private Identity.Client.IConfidentialClientApplication CreateClientApplication(string appId, string password, HttpClient customHttpClient = null)
{
var clientBuilder = Identity.Client.ConfidentialClientApplicationBuilder.Create(appId)
.WithAuthority(new Uri(OAuthEndpoint), ValidateAuthority)
.WithClientSecret(password);

if (customHttpClient != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,17 @@ public MsalAppCredentials(IConfidentialClientApplication clientApplication, stri
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2234:Pass system uri objects instead of strings", Justification = "Using string overload for legacy compatibility.")]
public MsalAppCredentials(string appId, string appPassword, string authority = null, string scope = null, bool validateAuthority = true, ILogger logger = null)
: this(
clientApplication: ConfidentialClientApplicationBuilder.Create(appId).WithClientSecret(appPassword).Build(),
clientApplication: null,
appId: appId,
authority: authority,
scope: scope,
validateAuthority: validateAuthority,
logger: logger)
{
_clientApplication = ConfidentialClientApplicationBuilder.Create(appId)
.WithAuthority(authority ?? OAuthEndpoint, validateAuthority)
.WithClientSecret(appPassword)
.Build();
}

/// <summary>
Expand All @@ -89,13 +93,17 @@ public MsalAppCredentials(string appId, string appPassword, string authority = n
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2234:Pass system uri objects instead of strings", Justification = "Using string overload for legacy compatibility.")]
public MsalAppCredentials(string appId, X509Certificate2 certificate, string authority = null, string scope = null, bool validateAuthority = true, ILogger logger = null)
: this(
clientApplication: ConfidentialClientApplicationBuilder.Create(appId).WithCertificate(certificate).Build(),
clientApplication: null,
appId: appId,
authority: authority,
scope: scope,
validateAuthority: validateAuthority,
logger: logger)
{
_clientApplication = ConfidentialClientApplicationBuilder.Create(appId)
.WithAuthority(authority ?? OAuthEndpoint, validateAuthority)
.WithCertificate(certificate)
.Build();
}

async Task<AuthenticatorResult> IAuthenticator.GetTokenAsync(bool forceRefresh)
Expand Down Expand Up @@ -168,7 +176,7 @@ private async Task<AuthenticatorResult> AcquireTokenAsync(bool forceRefresh = fa

// This means we acquired a valid token successfully. We can make our retry policy null.
return new AuthenticatorResult()
{
{
AccessToken = msalResult.AccessToken,
ExpiresOn = msalResult.ExpiresOn
};
Expand Down

0 comments on commit 332d26c

Please sign in to comment.