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

Can provide custom oAuthScope to MicrosoftGovernmentAppCredentials #935

Merged
merged 2 commits into from
Feb 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1482,7 +1482,7 @@ private CompletableFuture<AppCredentials> getAppCredentials(String appId, String

return credentialProvider.getAppPassword(appId).thenApply(appPassword -> {
AppCredentials credentials = channelProvider != null && channelProvider.isGovernment()
? new MicrosoftGovernmentAppCredentials(appId, appPassword)
? new MicrosoftGovernmentAppCredentials(appId, appPassword, scope)
: new MicrosoftAppCredentials(appId, appPassword);
appCredentialMap.put(cacheKey, credentials);
return credentials;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public abstract class AppCredentials implements ServiceClientCredentials {

private String appId;
private String authTenant;
private String authScope;
private Authenticator authenticator;

/**
Expand All @@ -45,7 +46,20 @@ public abstract class AppCredentials implements ServiceClientCredentials {
* @param withChannelAuthTenant Optional. The oauth token tenant.
*/
public AppCredentials(String withChannelAuthTenant) {
this(withChannelAuthTenant, AuthenticationConstants.TO_CHANNEL_FROM_BOT_OAUTH_SCOPE);
}

/**
* Initializes a new instance of the AppCredentials class.
*
* @param withChannelAuthTenant Optional. The oauth token tenant.
* @param withOAuthScope The scope for the token.
*/
public AppCredentials(String withChannelAuthTenant, String withOAuthScope) {
setChannelAuthTenant(withChannelAuthTenant);
authScope = StringUtils.isEmpty(withOAuthScope)
? AuthenticationConstants.TO_CHANNEL_FROM_BOT_OAUTH_SCOPE
: withOAuthScope;
}

/**
Expand Down Expand Up @@ -179,7 +193,7 @@ AuthenticationConstants.TO_CHANNEL_FROM_BOT_LOGIN_URL_TEMPLATE, getChannelAuthTe
* @return OAuth scope.
*/
public String oAuthScope() {
return AuthenticationConstants.TO_CHANNEL_FROM_BOT_OAUTH_SCOPE;
return authScope;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,25 @@ public MicrosoftAppCredentials(
setAppPassword(withAppPassword);
}

/**
* Initializes a new instance of the MicrosoftAppCredentials class.
*
* @param withAppId The Microsoft app ID.
* @param withAppPassword The Microsoft app password.
* @param withChannelAuthTenant Optional. The oauth token tenant.
* @param withOAuthScope The scope for the token.
*/
public MicrosoftAppCredentials(
String withAppId,
String withAppPassword,
String withChannelAuthTenant,
String withOAuthScope
) {
super(withChannelAuthTenant, withOAuthScope);
setAppId(withAppId);
setAppPassword(withAppPassword);
}

/**
* Gets the app password for this credential.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

package com.microsoft.bot.connector.authentication;

import org.apache.commons.lang3.StringUtils;

/**
* MicrosoftGovernmentAppCredentials auth implementation.
*/
Expand All @@ -14,7 +16,30 @@ public class MicrosoftGovernmentAppCredentials extends MicrosoftAppCredentials {
* @param password The Microsoft app password.
*/
public MicrosoftGovernmentAppCredentials(String appId, String password) {
super(appId, password);
super(
appId,
password,
null,
GovernmentAuthenticationConstants.TO_CHANNEL_FROM_BOT_OAUTH_SCOPE
);
}

/**
* Initializes a new instance of the MicrosoftGovernmentAppCredentials class.
*
* @param appId The Microsoft app ID.
* @param password The Microsoft app password.
* @param oAuthScope The scope for the token.
*/
public MicrosoftGovernmentAppCredentials(String appId, String password, String oAuthScope) {
super(
appId,
password,
null,
StringUtils.isEmpty(oAuthScope)
? GovernmentAuthenticationConstants.TO_CHANNEL_FROM_BOT_OAUTH_SCOPE
: oAuthScope
);
}

/**
Expand All @@ -35,14 +60,4 @@ public static MicrosoftGovernmentAppCredentials empty() {
public String oAuthEndpoint() {
return GovernmentAuthenticationConstants.TO_CHANNEL_FROM_BOT_LOGIN_URL;
}

/**
* Gets the Gov OAuth scope to use.
*
* @return The OAuth scope to use.
*/
@Override
public String oAuthScope() {
return GovernmentAuthenticationConstants.TO_CHANNEL_FROM_BOT_OAUTH_SCOPE;
}
}