-
Notifications
You must be signed in to change notification settings - Fork 2.4k
AADv2 Magic Code Not Returning Token From GetUserTokenAsync #4880
Description
Bot Info
- SDK Platform: .Net
- SDK Version: 3.15.3
- Active Channels: Web Chat, Twilio
- Deployment Environment: Azure App Service, Local Development
Issue Description
I followed the AADv2bot guide and created a bot, have it connected to AADv2, published to both Azure App Service and testing it locally. The bot is also successfully connected to the Twilio channel.
The bot both locally and via Azure App Service with the web channel will present the "Sign In" button card, prompt for me to enter my credentials and will successfully call the MS Graph and return my name.
Twilio however will send a long url for me to copy and paste into a browser, I then sign in via the browser and receive a 6 digit 'magic code' and enter that magic code back into the sms message back to the bot. However I am never authenticated with the magic code. I tried debugging this locally and manually calling await context.GetUserTokenAsync(ConnectionName, MagicCode) and it just results null.
In a breakpont that I set, the GetTokenResponse has null for Token and the magic code value I entered in as the NonTokenRepsonse. It appears the GetUserTokenAsync with the magic code is not working correctly.
Here I believe is the line of code returning the magic code back to me and not a token.
Code Example
private async Task ListMe(IDialogContext context, IAwaitable<GetTokenResponse> tokenResponse)
{
var token = await tokenResponse;
// Twilio SMS using Magic Code hits below but will not return a token.
if(token.NonTokenResponse != null)
{
var result = await context.GetUserTokenAsync(ConnectionName, token.NonTokenResponse);
// result is null when using magic code, the 'GetTokenDialog' calls this itself, but I was just verifying the value
if(result != null)
{
token.Token = result.Token;
}
}
var client = new SimpleGraphClient(token.Token);
var me = await client.GetMe();
//var manager = await client.GetManager();
await context.PostAsync($"Hello {me.DisplayName}! You are signed in!");
}
Reproduction Steps
- Run this example: https://github.com/Microsoft/BotBuilder/tree/master/CSharp/Samples/AadV2Bot
- Connect it to Twilio as an additional channel
- Send 'me' in a text message to the SMS number setup and connected to the bot framework.
- You will receive a long url to copy and put into your browser to authenticate
- After authentication you will receive a 6 digit code
- Enter the code back into SMS to the Twilio SMS number.
- The
GetTokenResponsewill not contain a token, just aNonTokenRepsonsewhich is the code that was entered in. - Unable to call the MS Graph client without a token.
Expected Behavior
I would expect that the GetUserTokenAsync which accepts the connection name and magic code would return a token per this line (https://github.com/Microsoft/BotBuilder/blob/master/CSharp/Library/Microsoft.Bot.Builder/Dialogs/GetTokenDialog.cs#L116).
Actual Results
Instead of returning a token when using the magic code a GetTokenRepsonse is returned where Token is null and NonTokenResponse contains the magic code that was entered into the text message.