从Azure B2C注册活动

时间:2016-03-19 04:04:09

标签: azure azure-ad-b2c

我怎么知道我网站上的某个人刚刚完成了注册' Azure B2C中的进程?我是否必须存储我自己的对象ID列表并检查它?我觉得无论如何我都不得不这样做......

3 个答案:

答案 0 :(得分:5)

如果在注册策略中选择了此声明,则会收到'newUser'布尔声明。这只会发送一次,所以你需要采取行动。

答案 1 :(得分:0)

是的,您需要存储一个对象ID列表&在您的业务逻辑中相应地验证。

答案 2 :(得分:0)

设法解决了这个问题...

第1步(Azure门户)

  • 在Azure门户中导航到ADB2C,单击“注册并登录”策略
  • 点击“应用程序声明”,并确保选中“用户是新用户”声明

仅当用户刚刚注册时,才会发送“用户是新用户”声明 enter image description here

第2步(代码)

//使用OpenIdConnectOptions

options.Events = new OpenIdConnectEvents()
{
            OnRedirectToIdentityProvider = OnRedirectToIdentityProvider,
            OnRemoteFailure = OnRemoteFailure,
            OnAuthorizationCodeReceived = OnAuthorizationCodeReceived,
            OnAuthenticationFailed = OnAuthenticationFailed,
            OnMessageReceived = OnMessageReceived,
            OnRedirectToIdentityProviderForSignOut = OnRedirectToIdentityProviderForSignOut,
            OnRemoteSignOut = OnRemoteSignOut,
            OnSignedOutCallbackRedirect = OnSignedOutCallbackRedirect,
            OnTicketReceived = _onTicketReceivedInternal,
            OnTokenResponseReceived = OnTokenResponseReceived,
            OnTokenValidated = OnTokenValidated,
            OnUserInformationReceived = OnUserInformationReceived
};

请注意_onTicketReceived内部任务...

private Task _onTicketReceivedInternal(TicketReceivedContext context)
{
        this.OnTicketReceived(context);

        //Check if new user
        Claim newUserClaim = context.Principal.Claims.ToList().FirstOrDefault(x => x.Type == "newUser");
        bool newUser = newUserClaim == null ? false : true;

        //Trigger event
        if (newUser)
            this.OnSignUp(context);


        return Task.FromResult(0);
}

//Custom method OnSignUp where an application can do something on user sign up
protected virtual Task OnSignUp(TicketReceivedContext context)
{
        return Task.FromResult(0);
}