0

Context: Azure AD B2C using Custom Policy.

I implemented "SignUp with email invitation" following https://github.com/azure-ad-b2c/samples/tree/master/policies/invite sample. The policy is based on https://github.com/azure-ad-b2c/samples/blob/master/policies/invite/policy/SignUpInvitation.xml. However, it seems after users complete the sign up (setting password), they are not logged in automatically but instead got redirect to login flow/login page. But I want them to logged in automatically.

The setup: when user clicks on the invitation link, it will hit .NET endpoint, which will trigger the signup flow.

[HttpGet("RedeemSignUp")]
public async Task<IActionResult> RedeemSignUpAsync(string tokenHint)
{
    // validate token hint
    // ....

    if (result.ValidationResult == "valid")
    {
        var items = new Dictionary<string, string>
        {
            { Microsoft.Identity.Web.Constants.Policy, ...config.SignUpInvitationPolicyId },
            { "id_token_hint", result.Token },
            { "returnurl, "/" }
        };

        var oAuthChallengeProperties = new OAuthChallengeProperties(items) 
        { 
            RedirectUri = "b2c-callback-url" // .NET endpoint 
        };

        return Challenge(oAuthChallengeProperties, "b2coidc");
    }

    // handle error
}

Also have the bit that the setup the id_token_hint on Startup.cs

services.AddMicrosoftIdentityWebApp(options =>
{
    Configuration.Bind(Constants.AzureAdB2C, options);
    options.Events ??= new OpenIdConnectEvents();
    var existingHandlers = options.Events.OnRedirectToIdentityProvider;
    options.Events.OnRedirectToIdentityProvider = context =>
    {
        existingHandlers(context);

        if (context.Properties.Items.ContainsKey("id_token_hint"))
        {                                
            context.ProtocolMessage.SetParameter("id_token_hint", context.Properties.Items["id_token_hint"]);
        }

        return Task.FromResult(0);
    };

    // ......
}

Question: How do I change it so that users can logged in automatically? Is that something with the custom policy or with the .NET setup?

Thanks

Dave D
  • 8,472
  • 4
  • 33
  • 45
WinterTho
  • 1
  • 1

0 Answers0