OAuthPrompt in v4.10.3 + Generic Oauth 2 + IdentityServer = No prompt is shown
See original GitHub issueOAuthPrompt in Microsoft.Bot.Builder.Dialogs v4.10.3 seems to be broken when using the connection name of “Generic Oauth 2” service provider - it is not displayed in Teams dialog with the bot, nor in WebChat.
To Reproduce
- Set up an IdentityServer instance locally, which needs to have the client configured as follows:
- ClientId:
your_client_id
- ClientSecret:
your_client_secret
- RedirectUris:
["https://token.botframework.com/.auth/web/redirect"]
- RequireConsent:
false
- AllowOfflineAccess:
true
, - AllowedScopes:
["openid", "profile"]
, - AllowedGrantTypes:
["authorization_code"]
, - RequirePkce:
false
, <-- necessary so Bot services can use it, as Bot services don’t seem to support PKCE - RefreshTokenUsage:
TokenUsage.ReUse
<-- the Bot services seem unable to handle the one-time refresh tokens
- Configure the Generic Oauth 2 service provider in Bot Channels registration so it points to the IdentityServer instance (you can use ngrok to host the IdentityServer instance) like this:
- Client id:
your_client_id
, - Client secret:
your_client_secret
, - Authorization URL:
https://<your identity server address>/connect/authorize
, - Token URL:
https://<your identity server address>/connect/token
, - Refresh URL:
https://<your identity server address>/connect/token
, - Scopes:
openid profile
- Start from the Teams Auth sample
- Edit appsettings.json to enter the valid credentials and use the connection name of AADv2 service provider
- Start the bot, type “hi” or whatever in Teams conversation with the bot and it will display a sign-in card.
- Stop the bot, go back to appsettings.json and change the connection name to have the name of the configured Generic Oauth 2 service provider connection name
- Start the bot again, type “hi” or whatever in Teams convo with the bot and it won’t display anything.
Screenshots
The configuration of Generic OAuth 2 service provider connection:
Additional context
This is the output from VS debugging:
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Information: Route matched with {action = "Post", controller = "Bot"}. Executing controller action with signature System.Threading.Tasks.Task PostAsync() on controller Microsoft.BotBuilderSamples.BotController (TeamsAuth).
Microsoft.Bot.Builder.Integration.AspNet.Core.BotFrameworkHttpAdapter: Information: Received an incoming activity. ActivityId: 1605218380039
Microsoft.BotBuilderSamples.DialogBot: Information: Running dialog with Message Activity.
TeamsAuth Information: 0 : 'hi' ==> beginDialog ==> MainDialog
TeamsAuth Information: 0 : 'hi' ==> beginDialog ==> WaterfallDialog
TeamsAuth Information: 0 : 'hi' ==> beginDialog ==> OAuthPrompt
Microsoft.Bot.Builder.Integration.AspNet.Core.BotFrameworkHttpAdapter: Information: GetTokenAsync: Acquired token using ADAL in 0.
Exception thrown: 'Microsoft.Rest.TransientFaultHandling.HttpRequestWithStatusException' in Microsoft.Rest.ClientRuntime.dll
Exception thrown: 'Microsoft.Rest.TransientFaultHandling.HttpRequestWithStatusException' in System.Private.CoreLib.dll
Microsoft.Bot.Builder.Integration.AspNet.Core.BotFrameworkHttpAdapter: Information: GetTokenAsync: Acquired token using ADAL in 0.
Microsoft.Bot.Builder.Integration.AspNet.Core.BotFrameworkHttpAdapter: Information: Sending activity. ReplyToId: 1605218380039
Microsoft.Bot.Builder.Integration.AspNet.Core.BotFrameworkHttpAdapter: Information: GetTokenAsync: Acquired token using ADAL in 0.
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Information: Executed action Microsoft.BotBuilderSamples.BotController.PostAsync (TeamsAuth) in 746.9577ms
Microsoft.AspNetCore.Routing.EndpointMiddleware: Information: Executed endpoint 'Microsoft.BotBuilderSamples.BotController.PostAsync (TeamsAuth)'
Microsoft.AspNetCore.Hosting.Diagnostics: Information: Request finished in 762.0714ms 200
Note that the sign in via this connection name works fine when used with messaging extensions:
new MessagingExtensionResult
{
Type = "auth",
SuggestedActions = new MessagingExtensionSuggestedAction
{
Actions = new List<CardAction>
{
new CardAction
{
Type = ActionTypes.OpenUrl,
Value = signInAddress,
Title = title,
}
}
}
};
Also, if I sign in through the messaging extension first, the OAuthPrompt
will correctly retrieve the access token for either requested connection name.
Also… I tried with an older 46.teams-auth sample which used v4.6.2 and it also worked fine. Pls fix 🥇
Issue Analytics
- State:
- Created 3 years ago
- Comments:13
Top Results From Across the Web
Teams Bot: OAuthPrompt not shown up - Microsoft Q&A
While updating Teams Bot I started facing an issue when I send OAuthPrompt card. By some reason it's not shown up in the...
Read more >OauthPrompt is not working inside of teams, works fine in ...
OauthPrompt is not working inside of Teams, works fine in Bot Framework Emulator and in 'Test in Web chat'. Inside of Teams app...
Read more >OAuthPrompt not shown up
My problem is that OAuth prompt card is not rendered at all in real chat (Teams web app or standalone app) but works...
Read more >OpenAM 10.1 > Administration Guide
This guide shows you how to configure, maintain, and troubleshoot OpenAM for single sign on and authorization, password reset, account lockout, cross-domain ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@jwiley84 no error message. Just doesn’t show up (you can try with the sample I mentioned, it’s not hard to reproduce). In our application, however,
BeginDialogAsync
method ofOAuthPrompt
throws an error with HTTP status code 404.@jwiley84 it seems I made a mistake when configuring the Generic Oauth2 provider after all. BotBuilder 4.10 is probably using the Token Exchange URL which wasn’t used by the previous BotBuilder versions. The problem was that I wrongfully set the value of Token Exchange URL to the token endpoint URL, where it had to be left blank. When I cleared the value, since it’s an optional field, the OAuthPrompt started to show, even with 4.10. Please accept my apologies for wasting your time on this issue.