Skip to content
This repository was archived by the owner on Dec 4, 2023. It is now read-only.

Commit 47e3e5c

Browse files
authored
Can provide custom oAuthScope to MicrosoftGovernmentAppCredentials (#935)
1 parent d5c2811 commit 47e3e5c

File tree

4 files changed

+61
-13
lines changed

4 files changed

+61
-13
lines changed

libraries/bot-builder/src/main/java/com/microsoft/bot/builder/BotFrameworkAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1482,7 +1482,7 @@ private CompletableFuture<AppCredentials> getAppCredentials(String appId, String
14821482

14831483
return credentialProvider.getAppPassword(appId).thenApply(appPassword -> {
14841484
AppCredentials credentials = channelProvider != null && channelProvider.isGovernment()
1485-
? new MicrosoftGovernmentAppCredentials(appId, appPassword)
1485+
? new MicrosoftGovernmentAppCredentials(appId, appPassword, scope)
14861486
: new MicrosoftAppCredentials(appId, appPassword);
14871487
appCredentialMap.put(cacheKey, credentials);
14881488
return credentials;

libraries/bot-connector/src/main/java/com/microsoft/bot/connector/authentication/AppCredentials.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public abstract class AppCredentials implements ServiceClientCredentials {
3737

3838
private String appId;
3939
private String authTenant;
40+
private String authScope;
4041
private Authenticator authenticator;
4142

4243
/**
@@ -45,7 +46,20 @@ public abstract class AppCredentials implements ServiceClientCredentials {
4546
* @param withChannelAuthTenant Optional. The oauth token tenant.
4647
*/
4748
public AppCredentials(String withChannelAuthTenant) {
49+
this(withChannelAuthTenant, AuthenticationConstants.TO_CHANNEL_FROM_BOT_OAUTH_SCOPE);
50+
}
51+
52+
/**
53+
* Initializes a new instance of the AppCredentials class.
54+
*
55+
* @param withChannelAuthTenant Optional. The oauth token tenant.
56+
* @param withOAuthScope The scope for the token.
57+
*/
58+
public AppCredentials(String withChannelAuthTenant, String withOAuthScope) {
4859
setChannelAuthTenant(withChannelAuthTenant);
60+
authScope = StringUtils.isEmpty(withOAuthScope)
61+
? AuthenticationConstants.TO_CHANNEL_FROM_BOT_OAUTH_SCOPE
62+
: withOAuthScope;
4963
}
5064

5165
/**
@@ -179,7 +193,7 @@ AuthenticationConstants.TO_CHANNEL_FROM_BOT_LOGIN_URL_TEMPLATE, getChannelAuthTe
179193
* @return OAuth scope.
180194
*/
181195
public String oAuthScope() {
182-
return AuthenticationConstants.TO_CHANNEL_FROM_BOT_OAUTH_SCOPE;
196+
return authScope;
183197
}
184198

185199
/**

libraries/bot-connector/src/main/java/com/microsoft/bot/connector/authentication/MicrosoftAppCredentials.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,25 @@ public MicrosoftAppCredentials(
5757
setAppPassword(withAppPassword);
5858
}
5959

60+
/**
61+
* Initializes a new instance of the MicrosoftAppCredentials class.
62+
*
63+
* @param withAppId The Microsoft app ID.
64+
* @param withAppPassword The Microsoft app password.
65+
* @param withChannelAuthTenant Optional. The oauth token tenant.
66+
* @param withOAuthScope The scope for the token.
67+
*/
68+
public MicrosoftAppCredentials(
69+
String withAppId,
70+
String withAppPassword,
71+
String withChannelAuthTenant,
72+
String withOAuthScope
73+
) {
74+
super(withChannelAuthTenant, withOAuthScope);
75+
setAppId(withAppId);
76+
setAppPassword(withAppPassword);
77+
}
78+
6079
/**
6180
* Gets the app password for this credential.
6281
*

libraries/bot-connector/src/main/java/com/microsoft/bot/connector/authentication/MicrosoftGovernmentAppCredentials.java

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
package com.microsoft.bot.connector.authentication;
55

6+
import org.apache.commons.lang3.StringUtils;
7+
68
/**
79
* MicrosoftGovernmentAppCredentials auth implementation.
810
*/
@@ -14,7 +16,30 @@ public class MicrosoftGovernmentAppCredentials extends MicrosoftAppCredentials {
1416
* @param password The Microsoft app password.
1517
*/
1618
public MicrosoftGovernmentAppCredentials(String appId, String password) {
17-
super(appId, password);
19+
super(
20+
appId,
21+
password,
22+
null,
23+
GovernmentAuthenticationConstants.TO_CHANNEL_FROM_BOT_OAUTH_SCOPE
24+
);
25+
}
26+
27+
/**
28+
* Initializes a new instance of the MicrosoftGovernmentAppCredentials class.
29+
*
30+
* @param appId The Microsoft app ID.
31+
* @param password The Microsoft app password.
32+
* @param oAuthScope The scope for the token.
33+
*/
34+
public MicrosoftGovernmentAppCredentials(String appId, String password, String oAuthScope) {
35+
super(
36+
appId,
37+
password,
38+
null,
39+
StringUtils.isEmpty(oAuthScope)
40+
? GovernmentAuthenticationConstants.TO_CHANNEL_FROM_BOT_OAUTH_SCOPE
41+
: oAuthScope
42+
);
1843
}
1944

2045
/**
@@ -35,14 +60,4 @@ public static MicrosoftGovernmentAppCredentials empty() {
3560
public String oAuthEndpoint() {
3661
return GovernmentAuthenticationConstants.TO_CHANNEL_FROM_BOT_LOGIN_URL;
3762
}
38-
39-
/**
40-
* Gets the Gov OAuth scope to use.
41-
*
42-
* @return The OAuth scope to use.
43-
*/
44-
@Override
45-
public String oAuthScope() {
46-
return GovernmentAuthenticationConstants.TO_CHANNEL_FROM_BOT_OAUTH_SCOPE;
47-
}
4863
}

0 commit comments

Comments
 (0)