private async Task SignIn(AppUser user)
        {
            var identity = await userManager.CreateIdentityAsync(
                user, DefaultAuthenticationTypes.ApplicationCookie);

            GetAuthenticationManager().SignIn(identity);
        }
示例#2
0
        public async Task <ClaimsIdentity> GenerateUserIdentityAsync(Microsoft.AspNet.Identity.UserManager <WfpUser, string> 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
            try
            {
                using (WfpictContext ctx = new WfpictContext())
                {
                    var userId = userIdentity.GetUserId();
                    var user   = ctx.Users.Include(x => x.Roles).FirstOrDefault(x => x.Id == userId);
                    if (user != null)
                    {
                        foreach (var role in user.Roles)
                        {
                            var roleClaims = ctx.RoleClaims.Include("Claim").Where(x => x.RoleId == role.RoleId);
                            foreach (var roleClaim in roleClaims)
                            {
                                userIdentity.AddClaim(new Claim(ClaimTypes.UserData, roleClaim.Claim.ClaimValue));
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // ignored
            }
            return(userIdentity);
        }
示例#3
0
        public async Task <ClaimsIdentity> GenerateUserIdentityAsync(Microsoft.AspNet.Identity.UserManager <MarketplaceUser> 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);
        }
示例#4
0
        public async Task <ClaimsIdentity> GenerateUserIdentityAsync(Microsoft.AspNet.Identity.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);
        }
示例#5
0
        //from webapi for OWin
        public async Task <ClaimsIdentity> GenerateUserIdentityAsync(Microsoft.AspNet.Identity.UserManager <AspNetIdentityUser, string> 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);
        }
示例#6
0
        public async Task <ClaimsIdentity> GenerateUserIdentityAsync(Microsoft.AspNet.Identity.UserManager <eCommerceUser> 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("Email", Email));
            userIdentity.AddClaim(new Claim("Picture", this.Picture != null ? this.Picture.URL : string.Empty));

            return(userIdentity);
        }