Skip to content
This repository was archived by the owner on Dec 4, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
3 changes: 3 additions & 0 deletions etc/bot-checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@
<module name="SuppressWarningsFilter" />

<module name="TreeWalker">
<!-- check for usage of literal equality "==" between string -->
<module name="StringLiteralEquality"/>

<module name="SuppressWarningsHolder" />
<module name="SuppressionCommentFilter"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ public CompletableFuture<Void> onTurn(TurnContext turnContext) {
case ActivityTypes.INSTALLATION_UPDATE:
return onInstallationUpdate(turnContext);

case ActivityTypes.END_OF_CONVERSATION:
return onEndOfConversationActivity(turnContext);

case ActivityTypes.TYPING:
return onTypingActivity(turnContext);

Expand Down Expand Up @@ -565,6 +568,17 @@ protected CompletableFuture<Void> onInstallationUpdateRemove(TurnContext turnCon
return CompletableFuture.completedFuture(null);
}

/**
* Override this in a derived class to provide logic specific to
* ActivityTypes.END_OF_CONVERSATION activities.
*
* @param turnContext The context object for this turn.
* @return A task that represents the work queued to execute.
*/
protected CompletableFuture<Void> onEndOfConversationActivity(TurnContext turnContext) {
return CompletableFuture.completedFuture(null);
}

/**
* Override this in a derived class to provide logic specific to
* ActivityTypes.Typing activities.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.microsoft.bot.connector.authentication.MicrosoftAppCredentials;
import com.microsoft.bot.connector.authentication.MicrosoftGovernmentAppCredentials;
import com.microsoft.bot.connector.authentication.SimpleCredentialProvider;
import com.microsoft.bot.connector.authentication.SkillValidation;
import com.microsoft.bot.connector.rest.RestConnectorClient;
import com.microsoft.bot.connector.rest.RestOAuthClient;
import com.microsoft.bot.schema.AadResourceUrls;
Expand Down Expand Up @@ -438,7 +439,10 @@ public CompletableFuture<InvokeResponse> processActivity(ClaimsIdentity identity

// The OAuthScope is also stored on the TurnState to get the correct
// AppCredentials if fetching a token is required.
String scope = getBotFrameworkOAuthScope();
String scope = SkillValidation.isSkillClaim(identity.claims())
? String.format("%s/.default", JwtTokenValidation.getAppIdFromClaims(identity.claims()))
: getBotFrameworkOAuthScope();

context.getTurnState().add(OAUTH_SCOPE_KEY, scope);

pipelineResult = createConnectorClient(activity.getServiceUrl(), identity, scope)
Expand Down Expand Up @@ -493,6 +497,13 @@ private CompletableFuture<String> generateCallerId(ClaimsIdentity claimsIdentity
return null;
}

// Is the activity from another bot?
if (SkillValidation.isSkillClaim(claimsIdentity.claims())) {
return String.format("%s%s",
CallerIdConstants.BOT_TO_BOT_PREFIX,
JwtTokenValidation.getAppIdFromClaims(claimsIdentity.claims()));
}

// Is the activity from Public Azure?
if (channelProvider == null || channelProvider.isPublicAzure()) {
return CallerIdConstants.PUBLIC_AZURE_CHANNEL;
Expand Down Expand Up @@ -1133,7 +1144,13 @@ public CompletableFuture<ConnectorClient> createConnectorClient(String serviceUr
}

if (botAppIdClaim != null) {
String scope = getBotFrameworkOAuthScope();
String scope = audience;

if (StringUtils.isBlank(audience)) {
scope = SkillValidation.isSkillClaim(claimsIdentity.claims())
? String.format("%s/.default", JwtTokenValidation.getAppIdFromClaims(claimsIdentity.claims()))
: getBotFrameworkOAuthScope();
}

return getAppCredentials(botAppIdClaim, scope)
.thenCompose(credentials -> getOrCreateConnectorClient(serviceUrl, credentials));
Expand Down Expand Up @@ -1236,8 +1253,8 @@ private CompletableFuture<AppCredentials> getAppCredentials(String appId, String
protected CompletableFuture<AppCredentials> buildAppCredentials(String appId, String scope) {
return credentialProvider.getAppPassword(appId).thenApply(appPassword -> {
AppCredentials credentials = channelProvider != null && channelProvider.isGovernment()
? new MicrosoftGovernmentAppCredentials(appId, appPassword, scope)
: new MicrosoftAppCredentials(appId, appPassword);
? new MicrosoftGovernmentAppCredentials(appId, appPassword, null, scope)
: new MicrosoftAppCredentials(appId, appPassword, null, scope);
return credentials;
});
}
Expand Down Expand Up @@ -1368,12 +1385,13 @@ public CompletableFuture<TokenResponse> getUserToken(TurnContext context, AppCre
));
}

OAuthClient client = createOAuthAPIClient(context, oAuthAppCredentials).join();
return client.getUserToken().getToken(
return createOAuthAPIClient(context, oAuthAppCredentials).thenCompose(client -> {
return client.getUserToken().getToken(
context.getActivity().getFrom().getId(),
connectionName,
context.getActivity().getChannelId(),
magicCode);
});
}

/**
Expand Down
Loading