@@ -286,10 +286,6 @@ public CompletableFuture<Void> continueConversation(
286286 ConversationReference reference ,
287287 BotCallbackHandler callback
288288 ) {
289- if (StringUtils .isEmpty (botAppId )) {
290- throw new IllegalArgumentException ("botAppId" );
291- }
292-
293289 if (reference == null ) {
294290 throw new IllegalArgumentException ("reference" );
295291 }
@@ -298,14 +294,14 @@ public CompletableFuture<Void> continueConversation(
298294 throw new IllegalArgumentException ("callback" );
299295 }
300296
297+ botAppId = botAppId == null ? "" : botAppId ;
298+
301299 // Hand craft Claims Identity.
302- HashMap <String , String > claims = new HashMap <String , String >() {
303- {
304- // Adding claims for both Emulator and Channel.
305- put (AuthenticationConstants .AUDIENCE_CLAIM , botAppId );
306- put (AuthenticationConstants .APPID_CLAIM , botAppId );
307- }
308- };
300+ // Adding claims for both Emulator and Channel.
301+ HashMap <String , String > claims = new HashMap <String , String >();
302+ claims .put (AuthenticationConstants .AUDIENCE_CLAIM , botAppId );
303+ claims .put (AuthenticationConstants .APPID_CLAIM , botAppId );
304+
309305 ClaimsIdentity claimsIdentity = new ClaimsIdentity ("ExternalBearer" , claims );
310306
311307 String audience = getBotFrameworkOAuthScope ();
@@ -382,12 +378,22 @@ public CompletableFuture<Void> continueConversation(
382378 context .getTurnState ().add (BOT_IDENTITY_KEY , claimsIdentity );
383379 context .getTurnState ().add (OAUTH_SCOPE_KEY , audience );
384380
385- pipelineResult = createConnectorClient (
386- reference .getServiceUrl (), claimsIdentity , audience
387- ).thenCompose (connectorClient -> {
388- context .getTurnState ().add (CONNECTOR_CLIENT_KEY , connectorClient );
389- return runPipeline (context , callback );
390- });
381+ String appIdFromClaims = JwtTokenValidation .getAppIdFromClaims (claimsIdentity .claims ());
382+ return credentialProvider .isValidAppId (appIdFromClaims )
383+ .thenCompose (isValidAppId -> {
384+ // If we receive a valid app id in the incoming token claims, add the
385+ // channel service URL to the trusted services list so we can send messages back.
386+ if (!StringUtils .isEmpty (appIdFromClaims ) && isValidAppId ) {
387+ AppCredentials .trustServiceUrl (reference .getServiceUrl ());
388+ }
389+
390+ return createConnectorClient (
391+ reference .getServiceUrl (), claimsIdentity , audience
392+ ).thenCompose (connectorClient -> {
393+ context .getTurnState ().add (CONNECTOR_CLIENT_KEY , connectorClient );
394+ return runPipeline (context , callback );
395+ });
396+ });
391397 } catch (Exception e ) {
392398 pipelineResult .completeExceptionally (e );
393399 }
0 commit comments