Ejemplo n.º 1
0
 public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
 {
     // Обратите внимание, что authenticationType должен совпадать с типом, определенным в CookieAuthenticationOptions.AuthenticationType
     var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
     // Здесь добавьте утверждения пользователя
     return userIdentity;
 }
Ejemplo n.º 2
0
        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");
        }
Ejemplo n.º 4
0
 public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<User, string> manager)
 {
     // Îáðàòèòå âíèìàíèå, ÷òî authenticationType äîëæåí ñîâïàäàòü ñ òèïîì, îïðåäåëåííûì â CookieAuthenticationOptions.AuthenticationType
     var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
     // Çäåñü äîáàâüòå óòâåðæäåíèÿ ïîëüçîâàòåëÿ
     return userIdentity;
 }
Ejemplo n.º 5
0
        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;
        }
Ejemplo n.º 6
0
 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;
 }
Ejemplo n.º 7
0
        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;
        }
Ejemplo n.º 8
0
 public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
 {
     // 请注意,authenticationType 必须与 CookieAuthenticationOptions.AuthenticationType 中定义的相应项匹配
     var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
     // 在此处添加自定义用户声明
     return userIdentity;
 }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 11
0
		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;
		}
Ejemplo n.º 12
0
 public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
 {
     // 注意 authenticationType 必須符合 CookieAuthenticationOptions.AuthenticationType 中定義的項目
     var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
     // 在這裡新增自訂使用者宣告
     return userIdentity;
 }
Ejemplo n.º 13
0
 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;
 }
Ejemplo n.º 14
0
 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;
 }
Ejemplo n.º 15
0
        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;
 }
Ejemplo n.º 17
0
 public async Task<ClaimsIdentity> GenerateUserIdentityAsync(
     UserManager<ApplicationUser> manager,
     string authenticationType)
 {
     var userIdentity = await manager.CreateIdentityAsync(this, authenticationType);
     return userIdentity;
 }
Ejemplo n.º 18
0
 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;
 }
Ejemplo n.º 19
0
 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;
 }
Ejemplo n.º 20
0
 public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<UserAccount> manager)
 {
     // authenticationType が CookieAuthenticationOptions.AuthenticationType で定義されているものと一致している必要があります
     var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
     // ここにカスタム ユーザー クレームを追加します
     return userIdentity;
 }
Ejemplo n.º 21
0
        public async Task <ClaimsIdentity> GenerateUserIdentityAsync(UserManager <ApplicationUser> manager)
        {
            // Обратите внимание, что authenticationType должен совпадать с типом, определенным в CookieAuthenticationOptions.AuthenticationType
            var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);

            // Здесь добавьте утверждения пользователя
            return(userIdentity);
        }
Ejemplo n.º 22
0
            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;
 } 
Ejemplo n.º 24
0
        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);
        }
Ejemplo n.º 25
0
        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;
        }
Ejemplo n.º 27
0
        public async Task <ClaimsIdentity> GenerateUserIdentityAsync(UserManager <ApplicationUser> manager)
        {
            // 注意 authenticationType 必須符合 CookieAuthenticationOptions.AuthenticationType 中定義的項目
            var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);

            // 在這裡新增自訂使用者宣告
            return(userIdentity);
        }
Ejemplo n.º 28
0
        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);
        }
Ejemplo n.º 29
0
 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;
 }
Ejemplo n.º 30
0
        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);
        }
Ejemplo n.º 31
0
        /// <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);
        }
Ejemplo n.º 32
0
        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);
        }
Ejemplo n.º 33
0
        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);
        }
Ejemplo n.º 34
0
        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);
        }
Ejemplo n.º 35
0
        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);
        }
Ejemplo n.º 37
0
        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;
        }
Ejemplo n.º 38
0
        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);
 }
Ejemplo n.º 40
0
        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);
        }
Ejemplo n.º 41
0
 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);
 }
Ejemplo n.º 42
0
        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;
 }
Ejemplo n.º 44
0
        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;
        }
Ejemplo n.º 45
0
        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);
        }
Ejemplo n.º 46
0
        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);
        }
Ejemplo n.º 47
0
        //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);
        }
Ejemplo n.º 48
0
        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);
        }
Ejemplo n.º 49
0
        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;
        }
Ejemplo n.º 50
0
        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);
        }
Ejemplo n.º 51
0
        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;
        }
Ejemplo n.º 52
0
        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);
        }
Ejemplo n.º 53
0
        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);
        }
Ejemplo n.º 54
0
        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));
        }
Ejemplo n.º 56
0
        // 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);
        }
Ejemplo n.º 57
0
 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;
 }
Ejemplo n.º 58
0
        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);
        }
Ejemplo n.º 59
0
		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;
		}
Ejemplo n.º 60
0
        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;
        }