⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
Some answers I found myself:
1. in https://github.com/Microsoft/botbuilder-tools/issues/713 but that was really not the place where I expected to find it.2. it seems that Azure Active Directory v2 is just a key name where you can also put another the connection name of another authentication type in. A bit confusing.3. it seems that it just works with the emulator when you use the msbot add command. More documentation on this would be welcome.It is unclear how the token response should be handled in the Enterprise Bot Template.
When follow the steps in https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-enterprise-template-deployment?view=azure-bot-service-4.0#authentication:
AddDialog(new AuthenticationDialog(_services.AuthConnectionName)); to the constructor of MainDialogvar authResult = await dc.BeginDialogAsync(nameof(AuthenticationDialog)); as the last statement in the OnStartAsync method of MainDialogthen I get the question to log in, but the FinishLoginDialog of AuthenticationDialog is never called. Instead the token response ends up in OnEventAsync of MainDialog.
I inserted
if (dc.Context.Activity.Name == "tokens/response")
{
var result = await dc.ContinueDialogAsync();
return;
}
// Check if there was an action submitted from intro card
else
ahead of https://github.com/Microsoft/AI/blob/440ef2eaa8b2dcff7d51fd7d169c7c1d7389e799/templates/Enterprise-Template/src/csharp/EnterpriseBotSample/Dialogs/Main/MainDialog.cs#L146, but I'm not sure whether that is the correct way to solve it.
How is this AuthenticationDialog supposed to be used?
@hansmbakker: have you figured out how to properly use AuthenticationDialog? i have the same problem here. can't find any solid solution to this one for days already. thanks
I don't know if it is the correct way, so I would really appreciate somebody from the bot builder team having a look at this.
@cleemullins @johnataylor since you work on the Bot Framework, could you help out here or could you suggest who can give us confirmation that this is the way to go?
I did the following:
MainDialog, update OnEventAsync(…) to :protected override async Task OnEventAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken))
{
if (dc.Context.Activity.Name == "tokens/response")
{
var result = await dc.ContinueDialogAsync();
return;
}
// Check if there was an action submitted from intro card
else if (dc.Context.Activity.Value != null)
{
dynamic value = dc.Context.Activity.Value;
if (value.action == "startOnboarding")
{
await dc.BeginDialogAsync(nameof(OnboardingDialog));
return;
}
//else if(value)
}
}
AddDialog(new AuthenticationDialog(_botServices.AuthConnectionName));WaterfallStep:public async Task<DialogTurnResult> CheckLogin(WaterfallStepContext sc, CancellationToken cancellationToken)
{
var adapter = sc.Context.Adapter as BotFrameworkAdapter;
var tokenResponse = await adapter.GetUserTokenAsync(sc.Context, _botServices.AuthConnectionName, null, cancellationToken);
if (tokenResponse is null)
{
await _responder.ReplyWith(sc.Context, CreateProjectResponses.ResponseIds.ShouldLoginMessage);
// If Bot Service does not have a token, send an OAuth card to sign in
var authResult = await sc.BeginDialogAsync(nameof(AuthenticationDialog));
return authResult;
}
else
{
return await sc.NextAsync(tokenResponse);
}
}
tokenResponse in the next WaterfallStep:TokenResponse tokenResponse = null;
if(sc.Result is TokenResponse)
{
tokenResponse = sc.Result as TokenResponse;
}
var user = await GetProfile(sc.Context, tokenResponse);
I think your solution here at least gives light to how its supposed to be used. @hansmbakker thank you
any updates? @hansmbakker @miojoffey
We've added this topic on auth that link to additional content for v4.
Most helpful comment
It is unclear how the token response should be handled in the Enterprise Bot Template.
When follow the steps in https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-enterprise-template-deployment?view=azure-bot-service-4.0#authentication:
AddDialog(new AuthenticationDialog(_services.AuthConnectionName));to the constructor ofMainDialogvar authResult = await dc.BeginDialogAsync(nameof(AuthenticationDialog));as the last statement in theOnStartAsyncmethod ofMainDialogthen I get the question to log in, but the
FinishLoginDialogofAuthenticationDialogis never called. Instead the token response ends up inOnEventAsyncofMainDialog.I inserted
ahead of https://github.com/Microsoft/AI/blob/440ef2eaa8b2dcff7d51fd7d169c7c1d7389e799/templates/Enterprise-Template/src/csharp/EnterpriseBotSample/Dialogs/Main/MainDialog.cs#L146, but I'm not sure whether that is the correct way to solve it.
How is this
AuthenticationDialogsupposed to be used?