diff --git a/libraries/Microsoft.Bot.Connector/Authentication/CertificateAppCredentials.cs b/libraries/Microsoft.Bot.Connector/Authentication/CertificateAppCredentials.cs index 5871b81371..a74e16330f 100644 --- a/libraries/Microsoft.Bot.Connector/Authentication/CertificateAppCredentials.cs +++ b/libraries/Microsoft.Bot.Connector/Authentication/CertificateAppCredentials.cs @@ -154,6 +154,7 @@ protected override Lazy 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) diff --git a/libraries/Microsoft.Bot.Connector/Authentication/MicrosoftAppCredentials.cs b/libraries/Microsoft.Bot.Connector/Authentication/MicrosoftAppCredentials.cs index c9ed8734fa..eb6b712212 100644 --- a/libraries/Microsoft.Bot.Connector/Authentication/MicrosoftAppCredentials.cs +++ b/libraries/Microsoft.Bot.Connector/Authentication/MicrosoftAppCredentials.cs @@ -172,6 +172,7 @@ protected override Lazy 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) diff --git a/libraries/Microsoft.Bot.Connector/Authentication/MsalAppCredentials.cs b/libraries/Microsoft.Bot.Connector/Authentication/MsalAppCredentials.cs index 583f087b3c..0bdb1bc47f 100644 --- a/libraries/Microsoft.Bot.Connector/Authentication/MsalAppCredentials.cs +++ b/libraries/Microsoft.Bot.Connector/Authentication/MsalAppCredentials.cs @@ -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(); } /// @@ -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 IAuthenticator.GetTokenAsync(bool forceRefresh) @@ -168,7 +176,7 @@ private async Task 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 };