in sdk/csharp/libraries/microsoft.bot.solutions/Authentication/MultiProviderAuthDialog.cs [104:171]
private async Task<DialogTurnResult> PromptForProviderAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
if (_authenticationConnections.Count == 1)
{
var result = _authenticationConnections.First().Name + "_" + CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;
return await stepContext.NextAsync(result).ConfigureAwait(false);
}
if (stepContext.Context.Adapter is IExtendedUserTokenProvider adapter)
{
var tokenStatusCollection = await adapter.GetTokenStatusAsync(stepContext.Context, _oauthCredentials, stepContext.Context.Activity.From.Id, null, cancellationToken).ConfigureAwait(false);
var matchingProviders = tokenStatusCollection.Where(p => (bool)p.HasToken && _authenticationConnections.Any(t => t.Name == p.ConnectionName)).ToList();
if (matchingProviders.Count == 1)
{
var authType = matchingProviders[0].ConnectionName;
return await stepContext.NextAsync(authType, cancellationToken).ConfigureAwait(false);
}
if (matchingProviders.Count > 1)
{
var choices = new List<Choice>();
foreach (var connection in matchingProviders)
{
choices.Add(new Choice
{
Action = new CardAction(ActionTypes.ImBack, connection.ConnectionName, value: connection.ConnectionName),
Value = connection.ConnectionName,
});
}
return await stepContext.PromptAsync(
DialogIds.ProviderPrompt,
new PromptOptions
{
Prompt = _responseManager.GetResponse(AuthenticationResponses.ConfiguredAuthProvidersPrompt),
Choices = choices,
},
cancellationToken).ConfigureAwait(false);
}
else
{
var choices = new List<Choice>();
foreach (var connection in _authenticationConnections)
{
choices.Add(new Choice
{
Action = new CardAction(ActionTypes.ImBack, connection.Name, value: connection.Name),
Value = connection.Name,
});
}
return await stepContext.PromptAsync(
DialogIds.ProviderPrompt,
new PromptOptions
{
Prompt = _responseManager.GetResponse(AuthenticationResponses.AuthProvidersPrompt),
Choices = choices,
},
cancellationToken).ConfigureAwait(false);
}
}
throw new Exception("The adapter doesn't support Token Handling.");
}