简体   繁体   English

将 Azure AD B2C 与机器人结合使用

[英]Using Azure AD B2C with Bot

I've created a bot in Azure that uses a SignInCard to give users the option to log-in or register as customers.我在 Azure 中创建了一个机器人,它使用SignInCard为用户提供登录或注册为客户的选项。 This is the SignInCard I currently have:这是我目前拥有的SignInCard

messageActivity.Attachments.Add(new SigninCard()
            {
                Buttons = new List<CardAction>()
                {
                    new CardAction()
                    {
                        Title = "Log in here",
                        DisplayText = "Log in here",
                        Value = "https://login.microsoftonline.com/XXXXXXXX.onmicrosoft.com/oauth2/v2.0/authorize?p=B2C_1_SiUp&client_id=XXXXX-XXXX-XXXX-XXXX-XXXXXXXd&nonce=defaultNonce&redirect_uri=http%3A%2F%2Flocalhost%3A3980%2Fapi%2Flogin&scope=openid&response_type=id_token&prompt=login",
                        Text = "Sign in/Register",
                        Type = ActionTypes.Signin,                        
                    }
                }                
            }.ToAttachment());

The bot correctly shows the card and when I click it, it opens the browser with the correct providers, that work perfectly (I can sign-in and register).机器人正确显示卡,当我单击它时,它会打开带有正确提供程序的浏览器,效果很好(我可以登录和注册)。

On my end, I have a Web API with a LoginController mapped to my Return Url (that is localhost:3980/api/login).最后,我有一个 Web API,其中LoginController映射到我的返回 URL (即 localhost:3980/api/login)。

To verify that the Return Url is being called, I put a breakpoint in LoginControl.Get :为了验证返回 URL 是否被调用,我在LoginControl.Get放置了一个断点:

public class LoginController : ApiController
{
    [HttpGet]
    public IHttpActionResult Get()
    {
        return Ok();     //The breakpoint here is hit!
    }
}

After login, the Get method is called as the breakpoint is hit, But what comes next?登录后,Get 方法在断点被命中时被调用,但是接下来会发生什么? I don't know how to proceed.我不知道如何继续。

The only think I've discovered is that the LoginController.Get method is being invoked by Azure B2C AD with a URL like this:我发现的唯一想法是,Azure B2C AD 使用如下 URL 调用LoginController.Get方法:

http://localhost:3980/api/login#id_token=eyJ0eXAi ... http://localhost:3980/api/login#id_token=eyJ0eXAi ...

I guess it's that URL what is being called because it shows in the address bar of my browser.我猜是那个 URL 被调用,因为它显示在我浏览器的地址栏中。

So, it's sending something called "id_token", but inside the Controller.Get method I cannot seem to have access to it.所以,它正在发送一个叫做“id_token”的东西,但在 Controller.Get 方法中,我似乎无法访问它。

What's the id_token? id_token 是什么? How to get it?如何获得?

AuthBot and also BotAuth are samples which contain authentication implementation approaches. AuthBotBotAuth是包含身份验证实现方法的示例。

You have to use Graph Api for to getting user principles using token received from authenticator service (More specific to Azure Active Directory).您必须使用 Graph Api 来使用从身份验证器服务接收的令牌获取用户原则(更具体到 Azure Active Directory)。 Token will receive in call back url which you have configured in AAD application.令牌将在您在 AAD 应用程序中配置的回调 url 中接收。

In samples, you will get a complete implementation of user authentication.在示例中,您将获得用户身份验证的完整实现。

Hope this will help you.希望这会帮助你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM