BotBuilderCommunity / botbuilder-community-dotnet

Part of the Bot Builder Community Project. Repository for extensions for the Bot Builder .NET SDK, including middleware, dialogs, recognizers and more.
MIT License
281 stars 172 forks source link

Handoff.ServiceNow raise error ServiceNowHandoff->No ServiceNow authentication token available #526

Open anandshenoy opened 1 year ago

anandshenoy commented 1 year ago

Hi Team,

I am working on integration the Servicenow Live agent chat with Bot framework. I used this library: Bot.Builder.Community.Components.Handoff.ServiceNow.

After following the steps provided with Oauth authentication, I am getting the error in handoff section, where I see the error "No ServiceNow Authentication token available".

Can anyone let me know if I am missing any step?

ztaylorMNP commented 1 year ago

I am having a similar issue. I am using the Handoff.ServiceNow component in a Bot Framework Composer solution published as a Power Virtual Agent skill. I have followed the instructions to configure both ServiceNow and my Bot Channel Oauth settings. Running the "Test connection" is successful and I receive a token. Testing the ServiceNow endpoints in Postman is also successful. However, when testing the bot, I see the "No ServiceNow authentication token available for this user" message.

Application Insights reports there is a 404 error occurring at: https://api.botframework.com/api/usertoken/GetToken?userId=[myuserid]&connectionName=CustomHandoffBot_OAuth

The error is occuring on line 37 of the ServiceNowHandoffMiddleware class:

//
// Bot.Builder.Community.Components.Handoff.ServiceNow.ServiceNowHandoffMiddleware.RouteActivityToExistingHandoff(ITurnContext turnContext, HandoffRecord handoffRecord)
//
 var tokenResponse = await userTokenClient.GetUserTokenAsync(turnContext.Activity.From.Id, _creds.ServiceNowAuthConnectionName, null, null, default(CancellationToken));

Bot Channel Oauth config is here: oauth-settings-redacted

I thought the issue might be in my App Registration Redirect URLs, so I tried adding https://token.botframework.com/.auth/web/redirect to the list with no success.

Any assistance/direction on this would be greatly appreciated.

surajmusmade commented 1 year ago

Hi Team, I am facing similar issue. Any update on the issue?

Thanks in advance!

ztaylorMNP commented 1 year ago

Hi,

I was later able to resolve the missing token issue by including an OAuth Login step in my Event Received activity like below:

image

The instructions had not been clear in stating that the OAuth step was required. I had the impression that OAuth only needed to be configured and the Handover component would handle the rest.

The result should be that the bot will present a "login" button in the chat for the user. User clicks the button, is taken to the Service Now login and prompted to "allow" the bot to access their account. The user is then redirected to a token page where they are prompted to copy a string token and paste it into the chat window to complete the sign-in.

NOTE: There does appear to be a bug in the Bot Framework Composer OAuth component where an "InputDialog is missing a prompt" exception is thrown. https://github.com/microsoft/BotFramework-Composer/issues/9624

surajmusmade commented 1 year ago

Thank you @ztaylorMNP, It's working now :)