我知道这是一个有点晚的答案,但它可能会对某人有所帮助。您需要在 Azure 中创建机器人服务并获取 Microsoft App Id 和 App Password。
然后可以提示用户登录。
private static OAuthPrompt Prompt(string connectionName)
{
return new OAuthPrompt(
LoginPromptName,
new OAuthPromptSettings
{
ConnectionName = connectionName,
Text = "Please Sign In",
Title = "Sign In",
Timeout = 300000, // User has 5 minutes to login (1000 * 60 * 5)
});
}
创建WaterfallStep 以登录Prompt。
private static async Task<DialogTurnResult> PromptStepAsync(WaterfallStepContext step, CancellationToken cancellationToken)
{
return await step.BeginDialogAsync(LoginPromptName, cancellationToken: cancellationToken);
}
接下来,您可以继续使用令牌做任何您想做的事情。
private static async Task<DialogTurnResult> LoginStepAsync(WaterfallStepContext step, CancellationToken cancellationToken)
{
// Get the token from the previous step. Note that we could also have gotten the
// token directly from the prompt itself. There is an example of this in the next method.
var tokenResponse = (TokenResponse)step.Result;
if (tokenResponse != null)
{
// use the token to do exciting things!
}
else
{
// If Bot Service does not have a token, send an OAuth card to sign in
}
await step.Context.SendActivityAsync("Login was not successful please try again.", cancellationToken: cancellationToken);
return Dialog.EndOfTurn;
}
关注this 指南了解更多信息。
您甚至可以为 Azure 设置其他 OAuth 提供程序,例如 Github、Facebook。为此,请转到 Bot Channels Registration 的设置并找到添加新连接选项。