public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager) { // Обратите внимание, что authenticationType должен совпадать с типом, определенным в CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); // Здесь добавьте утверждения пользователя return userIdentity; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager, ClaimsIdentity ext = null) { // Observe que o authenticationType precisa ser o mesmo que foi definido em CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); var claims = new List<Claim>(); if (!string.IsNullOrEmpty(CurrentClientId)) { claims.Add(new Claim("AspNet.Identity.ClientId", CurrentClientId)); } // Adicione novos Claims aqui // // Adicionando Claims externos capturados no login, que o facebook, twitter, etc enviam para essa aplicação. //No momento que o usuário loga, coneguimos pegar mais informações para cadastrar no Bd local. if (ext != null) { await SetExternalProperties(userIdentity, ext); } // Gerenciamento de Claims para informaçoes do usuario //claims.Add(new Claim("AdmRoles", "True")); userIdentity.AddClaims(claims); return userIdentity; }
public async Task<ActionResult> Login(LoginViewModel model) { // password for jwmcpeak is asdlfkf@RAG04 if (!ModelState.IsValid) { return View(model); } var userStore = new UserStore<IdentityUser>(); var userManager = new UserManager<IdentityUser>(userStore); var user = await userManager.FindAsync(model.Username, model.Password); if (user == null) { ModelState.AddModelError(string.Empty, "The user with the supplied credentials does not exist."); return View(model); } var authManager = HttpContext.GetOwinContext().Authentication; var userIdentity = await userManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie); authManager.SignIn(new AuthenticationProperties { IsPersistent = model.RememberMe }, userIdentity); return RedirectToAction("index", "home"); }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<User, string> manager) { // Îáðàòèòå âíèìàíèå, ÷òî authenticationType äîëæåí ñîâïàäàòü ñ òèïîì, îïðåäåëåííûì â CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); // Çäåñü äîáàâüòå óòâåðæäåíèÿ ïîëüçîâàòåëÿ return userIdentity; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager, ClaimsIdentity ext = null) { // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); var claims = new List<Claim>(); if (!string.IsNullOrEmpty(CurrentClientId)) { claims.Add(new Claim("AspNet.Identity.ClientId", CurrentClientId)); } // Adicione novos Claims aqui // // Adicionando Claims externos capturados no login if (ext != null) { await Global.SetExternalProperties(userIdentity, ext); } // Gerenciamento de Claims para informaçoes do usuario //claims.Add(new Claim("AdmRoles", "True")); userIdentity.AddClaims(claims); // Add custom user claims here return userIdentity; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager) { // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); // Add custom user claims here return userIdentity; }
public virtual async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<IdentityUser> manager, ClaimsIdentity ext = null) { // Observe que o authenticationType precisa ser o mesmo que foi definido em CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); var claims = new List<Claim>(); if (!string.IsNullOrEmpty(CurrentClientId)) { claims.Add(new Claim("AspNet.Identity.ClientId", CurrentClientId)); } // Adicione novos Claims aqui // // Adicionando Claims externos capturados no login if (ext != null) { await SetExternalProperties(userIdentity, ext); } // Gerenciamento de Claims para informaçoes do usuario //claims.Add(new Claim("AdmRoles", "True")); userIdentity.AddClaims(claims); return userIdentity; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager) { // 请注意,authenticationType 必须与 CookieAuthenticationOptions.AuthenticationType 中定义的相应项匹配 var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); // 在此处添加自定义用户声明 return userIdentity; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager) { // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); // Add custom user claims here ClaimsPrincipal claimsPrincipal = Thread.CurrentPrincipal as ClaimsPrincipal; //TODO: look-up the roles from the DB! string userId = userIdentity.Claims.Single(x => x.Type == ClaimTypes.NameIdentifier).Value; ApplicationDbContext context = new ApplicationDbContext(); Identity identity = context.Identities.Single(x => x.NameIdentifier == userId); userIdentity.AddClaim(new Claim(SpecialClaimTypes.UserId, identity.IdentityId.ToString(), ClaimValueTypes.Integer)); if (identity.SubscriptionIdentityRoles.Any()) { //get first found subscription //TODO: update the databasee to be in line with the entity model code first foreach (int subscriptionId in identity.SubscriptionIdentityRoles.Select(x=>x.SubscriptionId).Distinct()) { userIdentity.AddClaim(new Claim(SpecialClaimTypes.Subscription, subscriptionId.ToString())); } } return userIdentity; }
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { //context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" }); AuthContext _auth = new AuthContext(); UserManager<IdentityUser> _userManager = new UserManager<IdentityUser>(new UserStore<IdentityUser>(_auth)); RoleManager<IdentityRole> _roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(_auth)); AuthRepository _repo = new AuthRepository(); IdentityUser user = await _repo.FindUser(context.UserName, context.Password); if (user == null) { context.SetError("invalid_grant", "The user name or password is incorrect."); return; } var userIdentity = await _userManager.CreateIdentityAsync(user, context.Options.AuthenticationType); foreach (IdentityUserRole role in user.Roles) { var iRole = _roleManager.FindById(role.RoleId); userIdentity.AddClaim(new Claim(ClaimTypes.Role, iRole.Name)); } userIdentity.AddClaim(new Claim("sub", context.UserName)); userIdentity.AddClaim(new Claim("role", "user")); var ticket = new AuthenticationTicket(userIdentity, null); context.Validated(ticket); }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager) { // Notez qu'authenticationType doit correspondre à l'élément défini dans CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); // Ajouter les revendications personnalisées de l’utilisateur ici return userIdentity; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager) { // 注意 authenticationType 必須符合 CookieAuthenticationOptions.AuthenticationType 中定義的項目 var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); // 在這裡新增自訂使用者宣告 return userIdentity; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager) { // Observe que o authenticationType deve corresponder àquele definido em CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); // Adicionar declarações de usuário personalizado aqui return userIdentity; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<TravelWithMeUser> manager, string authenticationType) { // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(this, authenticationType); // Add custom user claims here return userIdentity; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ToyAppUser> manager) { if (manager == null) return null; return await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager, string authenticationType) { // Beachten Sie, dass der "authenticationType" mit dem in "CookieAuthenticationOptions.AuthenticationType" definierten Typ übereinstimmen muss. var userIdentity = await manager.CreateIdentityAsync(this, authenticationType); // Benutzerdefinierte Benutzeransprüche hier hinzufügen return userIdentity; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync( UserManager<ApplicationUser> manager, string authenticationType) { var userIdentity = await manager.CreateIdentityAsync(this, authenticationType); return userIdentity; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<User> manager) { // Tenga en cuenta que el valor de authenticationType debe coincidir con el definido en CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); // Agregar reclamaciones de usuario personalizado aquí return userIdentity; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<TicketDeskUser> manager) { // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); userIdentity.AddClaim(new Claim(ClaimTypes.GivenName, DisplayName)); return userIdentity; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<UserAccount> manager) { // authenticationType が CookieAuthenticationOptions.AuthenticationType で定義されているものと一致している必要があります var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); // ここにカスタム ユーザー クレームを追加します return userIdentity; }
public async Task <ClaimsIdentity> GenerateUserIdentityAsync(UserManager <ApplicationUser> manager) { // Обратите внимание, что authenticationType должен совпадать с типом, определенным в CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); // Здесь добавьте утверждения пользователя return(userIdentity); }
GenerateUserIdentity(UserManager<AppUser> manager) { var user = await manager .CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); return user; }
public static async Task<ClaimsIdentity> GenerateUserIdentityAsync(this ApplicationUser user, UserManager<ApplicationUser> manager) { // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie); // Add custom user claims here userIdentity.AddClaim(new Claim("EvilDuck.Id", user.Id)); return userIdentity; }
public async Task <ClaimsIdentity> GenerateUserIdentityAsync(UserManager <ApplicationUser> manager) { // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager?.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); // Add custom user claims here return(userIdentity); }
public async Task <ClaimsIdentity> GenerateUserIdentityAsync(UserManager <ApplicationUser> manager) { // 请注意,authenticationType 必须与 CookieAuthenticationOptions.AuthenticationType 中定义的相应项匹配 var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); // 在此处添加自定义用户声明 return(userIdentity); }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<User> manager, string authenticationType) { var userIdentity = await manager.CreateIdentityAsync(this, authenticationType); // Add custom user claims here return userIdentity; }
public async Task <ClaimsIdentity> GenerateUserIdentityAsync(UserManager <ApplicationUser> manager) { // 注意 authenticationType 必須符合 CookieAuthenticationOptions.AuthenticationType 中定義的項目 var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); // 在這裡新增自訂使用者宣告 return(userIdentity); }
public async Task <ClaimsIdentity> GenerateUserIdentityAsync(UserManager <ApplicationUser> manager) { // Tenga en cuenta que el valor de authenticationType debe coincidir con el definido en CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); // Agregar aquí notificaciones personalizadas de usuario return(userIdentity); }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<User> manager, string authenticationType = OAuthDefaults.AuthenticationType) { // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(this, authenticationType); // Add custom user claims here //userIdentity.AddClaim(new Claim("PSK", user.PSK)); return userIdentity; }
private async Task SignInAsync(User user, bool isPersistent) { SignInManager.SignOut(DefaultAuthenticationTypes.ExternalCookie); ClaimsIdentity identity = await _userManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie); SignInManager.SignIn(new AuthenticationProperties { IsPersistent = isPersistent }, identity); }
/// <summary> /// /// </summary> /// <param name="manager"></param> /// <returns></returns> public async Task <ClaimsIdentity> GenerateUserIdentityAsync(UserManager <ApplicationUser> manager) { ClaimsIdentity claimsIdentity = await manager.CreateIdentityAsync(this, "ApplicationCookie"); ClaimsIdentity userIdentity = claimsIdentity; claimsIdentity = (ClaimsIdentity)null; return(userIdentity); }
public async Task <ClaimsIdentity> GenerateUserIdentityAsync(UserManager <ApplicationUser> manager) { // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); // Add custom user claims here userIdentity.AddClaim(new Claim("TrackAndReport.MVC.Models.RegisterViewModel.Email", Email)); return(userIdentity); }
public async Task <ClaimsIdentity> GenerateUserIdentityAsync(UserManager <ApplicationUser> manager) { var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); userIdentity.AddClaim(new Claim("FirstName", FirstName)); userIdentity.AddClaim(new Claim("LastName", LastName)); return(userIdentity); }
private async Task signIn(MyIdentityUser myIdentityUser) { var identity = await userManager.CreateIdentityAsync(myIdentityUser, DefaultAuthenticationTypes.ApplicationCookie); var owinContext = Request.GetOwinContext(); var authManager = owinContext.Authentication; authManager.SignIn(identity); }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<Usuario> manager) { // Observe que o authenticationType deve corresponder àquele definido em CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); // Adicionar declarações de usuário personalizado aqui userIdentity.AddClaim(new Claim("Nome",Nome)); return userIdentity; }
private async Task SignInAsync(User user, ClaimsIdentity identity = null, bool rememberMe = false) { if (identity == null) { identity = await _userManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie); } AuthenticationManager.SignOutAllAndSignIn(identity, rememberMe); }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager) { // Element authenticationType musi pasować do elementu zdefiniowanego w elemencie CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); // Dodaj tutaj niestandardowe oświadczenia użytkownika return userIdentity; }
public async Task <ClaimsIdentity> GenerateUserIdentityAsync(UserManager <ApplicationUser> manager) { // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); // Add custom user claims here //userIdentity.AddClaim(new Claim("PortInfomaitonElectric", this.PortInfomaitonElectric.ToString())); return(userIdentity); }
private async Task SignInAsync(ApplicationUser user, bool isPersistent) { AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie); var identity = await UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie); // Add more custom claims here if you want. Eg HomeTown can be a claim for the User var homeclaim = new Claim(ClaimTypes.Country, user.HomeTown); identity.AddClaim(homeclaim); AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, identity); }
public async Task <ClaimsIdentity> GenerateUserIdentityAsync(UserManager <ApplicationUser> manager) { // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); // Add custom user claims here //public virtual ICollection<Enrolment> enrolments { get; set; } return(userIdentity); }
public static async Task ReauthorizeUserAsync(this ApplicationUser user) { IAuthenticationManager authenticationManager = HttpContext.Current.GetOwinContext().Authentication; authenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie); var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(db)); var identity = await userManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie); authenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = true }, identity); }
public async Task <ClaimsIdentity> GenerateUserIdentityAsync(UserManager <ApplicationUser> manager) { // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); // Add custom user claims here userIdentity.AddClaim(new Claim("DisplayName", DisplayName)); //identityHelper'da display name'i cekebilmek icin claim olusturduk !!!!!! return(userIdentity); }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager) { // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); //Voeg custom claims toe met name de naam en tijdzone van de user var claims = new List<Claim>(); userIdentity.AddClaims(claims); return userIdentity; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<User> manager) { // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); // Custom Claim for OrganizationId userIdentity.AddClaim(new Claim("OrganizationId", this.OrganizationId.ToString())); return userIdentity; }
public static async Task <ClaimsIdentity> CriarIdentityAsync(this APIUsuarioBO apiUsuarioBO, APIUsuario usuario, IUserTokenProvider <APIUsuarioIdentity, string> UserTokenProvider) { UserManager <APIUsuarioIdentity> userManager = new UserManager <APIUsuarioIdentity>(new APIUsuarioUserStore(apiUsuarioBO)); userManager.UserTokenProvider = UserTokenProvider; var user = usuario.CopyTo(new APIUsuarioIdentity()); var identity = await userManager.CreateIdentityAsync(user, OAuthDefaults.AuthenticationType); return(identity); }
public async Task <ClaimsIdentity> GenerateUserIdentityAsync( UserManager <User> manager, string authenticationType) { // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType ClaimsIdentity userIdentity = await manager.CreateIdentityAsync(this, authenticationType); // Add custom user claims here return(userIdentity); }
//METHODS public async Task <ClaimsIdentity> GenerateUserIdentityAsync(UserManager <ApplicationUser> manager) { // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); // Add custom user claims here userIdentity.AddClaim(new Claim("HouseholdId", HouseholdId.ToString())); userIdentity.AddClaim(new Claim("Name", this.FullName)); return(userIdentity); }
public async Task <ClaimsIdentity> GenerateUserIdentityAsync(UserManager <ApplicationUser> manager) { // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); userIdentity.AddClaim(new Claim("Tabemashou_Admin.Models.RegisterViewModel.NameIdentifier", NameIdentifier)); userIdentity.AddClaim(new Claim("Tabemashou_Admin.Models.RegisterViewModel.Email", Email)); return(userIdentity); }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager, string authenticationType) { // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(this, authenticationType); // Add custom user claims here // TODO: I hope this magical method is only called to create a user UserGames = new HashSet<Game>(); return userIdentity; }
public async Task <ClaimsIdentity> GenerateUserIdentityAsync(UserManager <ISUser> manager) { // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); userIdentity.AddClaim(new Claim("Fullname", this.FirstName + " " + this.LastName)); // Add custom user claims here return(userIdentity); }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser, long> manager) { // Note the authenticationType must match the one defined in // CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); // Add custom user claims here userIdentity.AddClaim(new Claim("FullName", FirstName + " " + MiddleName + " " + LastName)); return userIdentity; }
public async Task <ClaimsIdentity> GenerateUserIdentityAsync(UserManager <ApplicationUser> manager) { // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); // Add custom user claims here userIdentity.AddClaim(new Claim("username", this.user)); userIdentity.AddClaim(new Claim("userImage", this.userImgPath)); return(userIdentity); }
private async Task SignInAsync(ApplicationUser user, bool isPersistent) { AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie); var identity = await UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie); AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, identity); }
public async Task <ClaimsIdentity> GenerateUserIdentityAsync(UserManager <ApplicationUser, int> manager) { // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); // Add custom user claims here userIdentity.AddClaim(new Claim("UesrFullName", this.UserFullName ?? "PreUni-User")); return(userIdentity); }
public async Task <ActionResult> Login(LoginViewModel details) { string returnUrl = TempData["returnUrl"] == null ? "" : TempData["returnUrl"].ToString(); if (ModelState.IsValid) { AppUser user = await UserManager.FindAsync(details.UserName, details.Password); if (user == null) { ModelState.AddModelError("", "Невалидно потребителско име или парола!"); } else { ClaimsIdentity ident = await UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie); ident.AddClaims(AdministratorClaimsProvider.AddAdministratorAccessToRoles(this, ident)); AuthManager.SignOut(); AuthManager.SignIn(new AuthenticationProperties { IsPersistent = false }, ident); if (!user.IsGoogleAuthenticatorEnabled) { return(RedirectToAction("EnableGoogleAuthenticator", new { returnUrl = returnUrl, userName = user.UserName })); } Infrastructure.Helpers.SignInStatus result = await SignInHelper.PasswordSignIn(details.UserName, details.Password, false, shouldLockout : false); switch (result) { case Infrastructure.Helpers.SignInStatus.Success: return(RedirectToLocal(returnUrl)); case Infrastructure.Helpers.SignInStatus.LockedOut: return(View("Lockout")); case Infrastructure.Helpers.SignInStatus.RequiresTwoFactorAuthentication: return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl })); case Infrastructure.Helpers.SignInStatus.Failure: default: ModelState.AddModelError("", "Invalid login attempt."); return(View(details)); } } } TempData["returnUrl"] = returnUrl; return(View(details)); }
// TO-DO: Put function in static utility class, and pass in ApplicationUser as parameter public async Task <ClaimsIdentity> GenerateUserIdentityAsync(UserManager <ApplicationUser> manager) { // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); // TO-DO: Add application user fields as claim type // userIdentity.AddClaim(new Claim(ClaimTypes.GivenName, your_profile == null ? string.Empty : your_profile.FirstName)); // userIdentity.AddClaim(new Claim(ClaimTypes.Surname, your_profile == null ? string.Empty : your_profile.LastName)); return(userIdentity); }
public async virtual Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager, string authenticationType) { // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(this, authenticationType); userIdentity.AddClaim(new Claim(ClaimTypes.Name, UserName)); foreach (var identityRole in Roles) { userIdentity.AddClaim(new Claim(ClaimTypes.Role, identityRole.Name)); } return userIdentity; }
public async Task <ClaimsIdentity> GenerateUserIdentityAsync(UserManager <ApplicationUser> manager) { // Added this in an attempt to sort session log in issues, i.e sometimes log in fails //HttpContext.Current.Session["MyRunSession"] = "1"; //ControllerContext.HttpContext.Session.Add("MyRunSession", "1"); // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); // Add custom user claims here return(userIdentity); }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager) { // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); // Add custom user claims here if (!string.IsNullOrEmpty(this.DisplayName)) userIdentity.AddClaim(new Claim("DisplayName", this.DisplayName)); return userIdentity; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<BlogUser> manager) { var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); userIdentity.AddClaims(new List<Claim> { new Claim(ClaimTypes.Role, "user"), new Claim(ClaimTypes.Name, userIdentity.GetUserName()) }); return userIdentity; }