简体   繁体   中英

How to handle redirect request

I've created everything in B2C, and can call a URL (using Response.Redirect() from my asp.net page_load method) to display the [Microsoft] login screen.

After the User successfully logs in, the browser gets redirected to the supplied redirect_url (another asp.net page), as expected.

What I can't find is any guidance on how to handle that redirection request in order to extract the details about the logged-in user (the 'claims' I set in b2c).

I included the following &response_type=code+id_token in the URL and can see that both get included in the Request.Params collection.

I can't now find the docs which described how to create the URL which I'm calling. Any ideas on how to proceed? Thanks.

Here's the full redirect instruction, for completeness' sake (but there is AFAIK no issue with this):

        Response.Redirect("https://login.microsoftonline.com/" +
                          AuthenticationConstants.Tenant.ToString() +
                          "/oauth2/v2.0/authorize?p=" +
                          AuthenticationConstants.PolicySignIn.ToString() +
                          "&client_id=" +
                          AuthenticationConstants.ClientID.ToString() +
                          "&redirect_uri=" +
                          Server.HtmlEncode("https://localhost:44301/auth/Login.aspx") +
                          "&response_mode=query" +
                          "&response_type=code+id_token" +
                          "&scope=openid " + AuthenticationConstants.ClientID.ToString()
                         );

The claims you set in B2C are included in the id_token. ASP.Net makes these available for you via ClaimsPrincipal.Current.FindFirst('nameOfTheClaim') .

From the Azure AD B2C guide for an ASP.Net Web App :

 // Controllers\HomeController.cs

 [Authorize]
 public ActionResult Claims()
 {
     Claim displayName = ClaimsPrincipal.Current.FindFirst(ClaimsPrincipal.Current.Identities.First().NameClaimType);
     ViewBag.DisplayName = displayName != null ? displayName.Value : string.Empty;
     return View();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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