Skip to content
This repository was archived by the owner on Jan 5, 2026. It is now read-only.

Commit 435c507

Browse files
fangyangciTracy Boehrer
authored andcommitted
fix: USGovSingleTenant OAuthEndpoint (#6714)
* fixUSGovSingleTenant * Add UT * Rollback AuthTenant Property Name * The Ctor do contains the old ones, Add Ctor to ApiCompatBaseline
1 parent 02ec769 commit 435c507

10 files changed

Lines changed: 174 additions & 142 deletions

ApiCompatBaseline.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,18 @@ TypesMustExist : Type 'Microsoft.Bot.Builder.Azure.CosmosDbCustomClientOptions'
33
TypesMustExist : Type 'Microsoft.Bot.Builder.Azure.CosmosDbStorage' does not exist in the implementation but it does exist in the contract.
44
TypesMustExist : Type 'Microsoft.Bot.Builder.Azure.CosmosDbStorageOptions' does not exist in the implementation but it does exist in the contract.
55

6+
MembersMustExist : Member 'Microsoft.Bot.Connector.Authentication.MicrosoftAppCredentials..ctor(System.String, System.String)' does not exist in the implementation but it does exist in the contract.
7+
MembersMustExist : Member 'Microsoft.Bot.Connector.Authentication.MicrosoftAppCredentials..ctor(System.String, System.String, System.Net.Http.HttpClient)' does not exist in the implementation but it does exist in the contract.
8+
MembersMustExist : Member 'Microsoft.Bot.Connector.Authentication.MicrosoftAppCredentials..ctor(System.String, System.String, System.Net.Http.HttpClient, Microsoft.Extensions.Logging.ILogger)' does not exist in the implementation but it does exist in the contract.
9+
MembersMustExist : Member 'Microsoft.Bot.Connector.Authentication.MicrosoftAppCredentials..ctor(System.String, System.String, System.String, System.Net.Http.HttpClient)' does not exist in the implementation but it does exist in the contract.
10+
MembersMustExist : Member 'Microsoft.Bot.Connector.Authentication.MicrosoftAppCredentials..ctor(System.String, System.String, System.String, System.Net.Http.HttpClient, Microsoft.Extensions.Logging.ILogger)' does not exist in the implementation but it does exist in the contract.
11+
MembersMustExist : Member 'Microsoft.Bot.Connector.Authentication.MicrosoftGovernmentAppCredentials..ctor(System.String, System.String, System.Net.Http.HttpClient)' does not exist in the implementation but it does exist in the contract.
12+
MembersMustExist : Member 'Microsoft.Bot.Connector.Authentication.MicrosoftGovernmentAppCredentials..ctor(System.String, System.String, System.Net.Http.HttpClient, Microsoft.Extensions.Logging.ILogger)' does not exist in the implementation but it does exist in the contract.
13+
614
TypesMustExist : Type 'Microsoft.Bot.Connector.Authentication.AdalAuthenticator' does not exist in the implementation but it does exist in the contract.
715
MembersMustExist : Member 'Microsoft.Bot.Connector.Authentication.AppCredentials.BuildAuthenticator()' does not exist in the implementation but it does exist in the contract.
816
CannotAddAbstractMembers : Member 'Microsoft.Bot.Connector.Authentication.AppCredentials.BuildIAuthenticator()' is abstract in the implementation but is missing in the contract.
917
MembersMustExist : Member 'Microsoft.Bot.Connector.Authentication.CertificateAppCredentials..ctor(Microsoft.IdentityModel.Clients.ActiveDirectory.ClientAssertionCertificate, System.String, System.Net.Http.HttpClient, Microsoft.Extensions.Logging.ILogger)' does not exist in the implementation but it does exist in the contract.
1018
MembersMustExist : Member 'Microsoft.Bot.Connector.Authentication.CertificateAppCredentials.BuildAuthenticator()' does not exist in the implementation but it does exist in the contract.
11-
MembersMustExist : Member 'Microsoft.Bot.Connector.Authentication.MicrosoftAppCredentials.BuildAuthenticator()' does not exist in the implementation but it does exist in the contract.
19+
MembersMustExist : Member 'Microsoft.Bot.Connector.Authentication.MicrosoftAppCredentials.BuildAuthenticator()' does not exist in the implementation but it does exist in the contract.
20+

libraries/Microsoft.Bot.Connector/Authentication/AppCredentials.cs

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public abstract class AppCredentials : ServiceClientCredentials
3434
/// </summary>
3535
private Lazy<IAuthenticator> _authenticator;
3636

37+
private string _oAuthScope;
38+
3739
/// <summary>
3840
/// Initializes a new instance of the <see cref="AppCredentials"/> class.
3941
/// </summary>
@@ -54,7 +56,7 @@ public AppCredentials(string channelAuthTenant = null, HttpClient customHttpClie
5456
/// <param name="oAuthScope">The scope for the token.</param>
5557
public AppCredentials(string channelAuthTenant = null, HttpClient customHttpClient = null, ILogger logger = null, string oAuthScope = null)
5658
{
57-
OAuthScope = string.IsNullOrWhiteSpace(oAuthScope) ? AuthenticationConstants.ToChannelFromBotOAuthScope : oAuthScope;
59+
_oAuthScope = oAuthScope;
5860
ChannelAuthTenant = channelAuthTenant;
5961
CustomHttpClient = customHttpClient;
6062
Logger = logger ?? NullLogger.Instance;
@@ -74,13 +76,15 @@ public AppCredentials(string channelAuthTenant = null, HttpClient customHttpClie
7476
/// <value>
7577
/// Tenant to be used for channel authentication.
7678
/// </value>
77-
public string ChannelAuthTenant
79+
public virtual string ChannelAuthTenant
7880
{
79-
get => string.IsNullOrEmpty(AuthTenant) ? AuthenticationConstants.DefaultChannelAuthTenant : AuthTenant;
81+
get => string.IsNullOrEmpty(AuthTenant)
82+
? DefaultChannelAuthTenant
83+
: AuthTenant;
8084
set
8185
{
8286
// Advanced user only, see https://aka.ms/bots/tenant-restriction
83-
var endpointUrl = string.Format(CultureInfo.InvariantCulture, AuthenticationConstants.ToChannelFromBotLoginUrlTemplate, value);
87+
var endpointUrl = string.Format(CultureInfo.InvariantCulture, ToChannelFromBotLoginUrlTemplate, value);
8488

8589
if (Uri.TryCreate(endpointUrl, UriKind.Absolute, out _))
8690
{
@@ -99,7 +103,7 @@ public string ChannelAuthTenant
99103
/// <value>
100104
/// The OAuth endpoint to use.
101105
/// </value>
102-
public virtual string OAuthEndpoint => string.Format(CultureInfo.InvariantCulture, AuthenticationConstants.ToChannelFromBotLoginUrlTemplate, ChannelAuthTenant);
106+
public virtual string OAuthEndpoint => string.Format(CultureInfo.InvariantCulture, ToChannelFromBotLoginUrlTemplate, ChannelAuthTenant);
103107

104108
/// <summary>
105109
/// Gets a value indicating whether to validate the Authority.
@@ -115,7 +119,9 @@ public string ChannelAuthTenant
115119
/// <value>
116120
/// The OAuth scope to use.
117121
/// </value>
118-
public virtual string OAuthScope { get; }
122+
public virtual string OAuthScope => string.IsNullOrEmpty(_oAuthScope)
123+
? ToChannelFromBotOAuthScope
124+
: _oAuthScope;
119125

120126
/// <summary>
121127
/// Gets or sets the channel auth token tenant for this credential.
@@ -141,6 +147,26 @@ public string ChannelAuthTenant
141147
/// </value>
142148
protected ILogger Logger { get; set; }
143149

150+
/// <summary>
151+
/// Gets DefaultChannelAuthTenant.
152+
/// </summary>
153+
/// <value>DefaultChannelAuthTenant.</value>
154+
protected virtual string DefaultChannelAuthTenant => AuthenticationConstants.DefaultChannelAuthTenant;
155+
156+
/// <summary>
157+
/// Gets ToChannelFromBotOAuthScope.
158+
/// </summary>
159+
/// <value>ToChannelFromBotOAuthScope.</value>
160+
protected virtual string ToChannelFromBotOAuthScope => AuthenticationConstants.ToChannelFromBotOAuthScope;
161+
162+
/// <summary>
163+
/// Gets ToChannelFromBotLoginUrlTemplate.
164+
/// </summary>
165+
/// <value>ToChannelFromBotLoginUrlTemplate.</value>
166+
#pragma warning disable CA1056 // Uri properties should not be strings
167+
protected virtual string ToChannelFromBotLoginUrlTemplate => AuthenticationConstants.ToChannelFromBotLoginUrlTemplate;
168+
#pragma warning restore CA1056 // Uri properties should not be strings
169+
144170
/// <summary>
145171
/// Adds the host of service url to <see cref="MicrosoftAppCredentials"/> trusted hosts.
146172
/// </summary>

libraries/Microsoft.Bot.Connector/Authentication/GovernmentAuthenticationConstants.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,24 @@ public static class GovernmentAuthenticationConstants
1414
public const string ChannelService = "https://botframework.azure.us";
1515

1616
/// <summary>
17-
/// TO GOVERNMENT CHANNEL FROM BOT: Login URL.
17+
/// TO CHANNEL FROM BOT: Login URL.
18+
///
19+
/// DEPRECATED. For binary compat only.
1820
/// </summary>
1921
public const string ToChannelFromBotLoginUrl = "https://login.microsoftonline.us/MicrosoftServices.onmicrosoft.us";
2022

23+
/// <summary>
24+
/// TO CHANNEL FROM BOT: Login URL template string. Bot developer may specify
25+
/// which tenant to obtain an access token from. By default, the channels only
26+
/// accept tokens from "MicrosoftServices.onmicrosoft.us". For more details see https://aka.ms/bots/tenant-restriction.
27+
/// </summary>
28+
public const string ToChannelFromBotLoginUrlTemplate = "https://login.microsoftonline.us/{0}";
29+
30+
/// <summary>
31+
/// The default tenant to acquire bot to channel token from.
32+
/// </summary>
33+
public const string DefaultChannelAuthTenant = "MicrosoftServices.onmicrosoft.us";
34+
2135
/// <summary>
2236
/// TO GOVERNMENT CHANNEL FROM BOT: OAuth scope to request.
2337
/// </summary>

libraries/Microsoft.Bot.Connector/Authentication/GovernmentCloudBotFrameworkAuthentication.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ internal class GovernmentCloudBotFrameworkAuthentication : BuiltinBotFrameworkAu
1212
public GovernmentCloudBotFrameworkAuthentication(ServiceClientCredentialsFactory credentialFactory, AuthenticationConfiguration authConfiguration, IHttpClientFactory httpClientFactory, ILogger logger = null)
1313
: base(
1414
GovernmentAuthenticationConstants.ToChannelFromBotOAuthScope,
15-
GovernmentAuthenticationConstants.ToChannelFromBotLoginUrl,
15+
GovernmentAuthenticationConstants.ToChannelFromBotLoginUrlTemplate,
1616
CallerIdConstants.USGovChannel,
1717
GovernmentAuthenticationConstants.ChannelService,
1818
GovernmentAuthenticationConstants.OAuthUrlGov,

libraries/Microsoft.Bot.Connector/Authentication/MicrosoftAppCredentials.cs

Lines changed: 2 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -38,39 +38,6 @@ public class MicrosoftAppCredentials : AppCredentials
3838
/// </summary>
3939
public static readonly MicrosoftAppCredentials Empty = new MicrosoftAppCredentials(null, null);
4040

41-
/// <summary>
42-
/// Initializes a new instance of the <see cref="MicrosoftAppCredentials"/> class.
43-
/// </summary>
44-
/// <param name="appId">The Microsoft app ID.</param>
45-
/// <param name="password">The Microsoft app password.</param>
46-
public MicrosoftAppCredentials(string appId, string password)
47-
: this(appId, password, null, null, null, null)
48-
{
49-
}
50-
51-
/// <summary>
52-
/// Initializes a new instance of the <see cref="MicrosoftAppCredentials"/> class.
53-
/// </summary>
54-
/// <param name="appId">The Microsoft app ID.</param>
55-
/// <param name="password">The Microsoft app password.</param>
56-
/// <param name="customHttpClient">Optional <see cref="HttpClient"/> to be used when acquiring tokens.</param>
57-
public MicrosoftAppCredentials(string appId, string password, HttpClient customHttpClient)
58-
: this(appId, password, null, customHttpClient)
59-
{
60-
}
61-
62-
/// <summary>
63-
/// Initializes a new instance of the <see cref="MicrosoftAppCredentials"/> class.
64-
/// </summary>
65-
/// <param name="appId">The Microsoft app ID.</param>
66-
/// <param name="password">The Microsoft app password.</param>
67-
/// <param name="customHttpClient">Optional <see cref="HttpClient"/> to be used when acquiring tokens.</param>
68-
/// <param name="logger">Optional <see cref="ILogger"/> to gather telemetry data while acquiring and managing credentials.</param>
69-
public MicrosoftAppCredentials(string appId, string password, HttpClient customHttpClient, ILogger logger)
70-
: this(appId, password, null, customHttpClient, logger)
71-
{
72-
}
73-
7441
/// <summary>
7542
/// Initializes a new instance of the <see cref="MicrosoftAppCredentials"/> class.
7643
/// </summary>
@@ -79,36 +46,11 @@ public MicrosoftAppCredentials(string appId, string password, HttpClient customH
7946
/// <param name="customHttpClient">Optional <see cref="HttpClient"/> to be used when acquiring tokens.</param>
8047
/// <param name="logger">Optional <see cref="ILogger"/> to gather telemetry data while acquiring and managing credentials.</param>
8148
/// <param name="oAuthScope">The scope for the token.</param>
82-
public MicrosoftAppCredentials(string appId, string password, HttpClient customHttpClient, ILogger logger, string oAuthScope)
49+
public MicrosoftAppCredentials(string appId, string password, HttpClient customHttpClient = null, ILogger logger = null, string oAuthScope = null)
8350
: this(appId, password, null, customHttpClient, logger, oAuthScope)
8451
{
8552
}
8653

87-
/// <summary>
88-
/// Initializes a new instance of the <see cref="MicrosoftAppCredentials"/> class.
89-
/// </summary>
90-
/// <param name="appId">The Microsoft app ID.</param>
91-
/// <param name="password">The Microsoft app password.</param>
92-
/// <param name="channelAuthTenant">Optional. The oauth token tenant.</param>
93-
/// <param name="customHttpClient">Optional <see cref="HttpClient"/> to be used when acquiring tokens.</param>
94-
public MicrosoftAppCredentials(string appId, string password, string channelAuthTenant, HttpClient customHttpClient)
95-
: this(appId, password, channelAuthTenant, customHttpClient, null)
96-
{
97-
}
98-
99-
/// <summary>
100-
/// Initializes a new instance of the <see cref="MicrosoftAppCredentials"/> class.
101-
/// </summary>
102-
/// <param name="appId">The Microsoft app ID.</param>
103-
/// <param name="password">The Microsoft app password.</param>
104-
/// <param name="channelAuthTenant">Optional. The oauth token tenant.</param>
105-
/// <param name="customHttpClient">Optional <see cref="HttpClient"/> to be used when acquiring tokens.</param>
106-
/// <param name="logger">Optional <see cref="ILogger"/> to gather telemetry data while acquiring and managing credentials.</param>
107-
public MicrosoftAppCredentials(string appId, string password, string channelAuthTenant, HttpClient customHttpClient, ILogger logger = null)
108-
: this(appId, password, channelAuthTenant, customHttpClient, logger, null)
109-
{
110-
}
111-
11254
/// <summary>
11355
/// Initializes a new instance of the <see cref="MicrosoftAppCredentials"/> class.
11456
/// </summary>
@@ -118,7 +60,7 @@ public MicrosoftAppCredentials(string appId, string password, string channelAuth
11860
/// <param name="customHttpClient">Optional <see cref="HttpClient"/> to be used when acquiring tokens.</param>
11961
/// <param name="logger">Optional <see cref="ILogger"/> to gather telemetry data while acquiring and managing credentials.</param>
12062
/// <param name="oAuthScope">The scope for the token.</param>
121-
public MicrosoftAppCredentials(string appId, string password, string channelAuthTenant, HttpClient customHttpClient, ILogger logger = null, string oAuthScope = null)
63+
public MicrosoftAppCredentials(string appId, string password, string channelAuthTenant, HttpClient customHttpClient = null, ILogger logger = null, string oAuthScope = null)
12264
: base(channelAuthTenant, customHttpClient, logger, oAuthScope)
12365
{
12466
MicrosoftAppId = appId;

0 commit comments

Comments
 (0)