Skip to content

Instantly share code, notes, and snippets.

@poojarsn
Created November 12, 2022 08:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save poojarsn/a63c4cae5bdeefa34e7c201d6416956e to your computer and use it in GitHub Desktop.
Save poojarsn/a63c4cae5bdeefa34e7c201d6416956e to your computer and use it in GitHub Desktop.
//Azure AD B2C Owin Context is null , once the token is acquired by authorization code flow
//Set Authentication Manager profile
var authenticated = HttpContext.GetOwinContext().Authentication.AuthenticateAsync("ExternalCookie");
// Send Access Token bearer to api to get logged user details
var loggedInUser = AuthenticationManager.BuildVirtualUser(string.Format(@"{0}\{1}", "external", "User-ID"), true);
loggedInUser.RuntimeSettings.AddedRoles.Add(authenticated.Result.Identity.Claims.First().Value);
loggedInUser.Profile.FullName = string.Format("{0} {1}", authenticated.Result.Identity.Name, authenticated.Result.Identity.Claims.Last().Value);
loggedInUser.Profile.Save();
AuthenticationManager.Login(loggedInUser);
userObject.IsAuthenticated = User.Identity.IsAuthenticated;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment