guglschool.blogg.se

Add custom token skrumble
Add custom token skrumble









add custom token skrumble

Identity.AddClaim(new Claim("your claims name", "your claim data for this user")) Īnd then in startup.cs of your project add this code(after services.AddIdentity(.) ) services.AddScoped, MyUserClaimsPrincipalFactory>() Identity.AddClaim(new Claim(ClaimTypes.MobilePhone, user.PhoneNumber ? "")) Identity.AddClaim(new Claim(ClaimTypes.Email, user.Email)) Identity.AddClaim(new Claim(ClaimTypes.GivenName, user.FullName ? "")) Var identity = await base.GenerateClaimsAsync(user) Protected override async Task GenerateClaimsAsync(ApplicationUser user) : base(userManager, roleManager, optionsAccessor)

add custom token skrumble

Hoping someone could nudge me to the correct answer.įirst One is you must create new class as bottom( reference): public class MyUserClaimsPrincipalFactory : UserClaimsPrincipalFactory

#Add custom token skrumble full#

I can get the username and full name with no problem but group id causes an object null error. String s= identity.FindFirst("GroupID").Value TempData = identity.FindFirst(ClaimTypes.Name).Value Var identity = (ClaimsIdentity)User.Identity In my login partial I tried to get the value by doing this public ActionResult _LoginPartial() ModelState.AddModelError("", "Invalid login attempt.") Return RedirectToAction("Index", "Home") Var id = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie) UserViewModel curUser = userModel.GetUserDetails(model.Username) Ĭlaims.Add(new Claim(ClaimTypes.WindowsAccountName, curUser.Username)) Ĭlaims.Add(new Claim(ClaimTypes.Name,curUser.Fullname)) Ĭlaims.Add(new Claim(ClaimTypes.Role, "")) Ĭlaims.Add(new Claim("GroupID", ())) If(CommonHelper.ValidateADUser(model.Username,model.Password))

add custom token skrumble

UserViewModel userModel = new UserViewModel() I did something like this in my Login public ActionResult Login(LoginViewModel model, string returnUrl) I need to add custom claims like "GroupID" so i can easily access it on the different pages. New to OWIN authentication and finding it hard to create my own owin claim types.











Add custom token skrumble