Example #1
0
 public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
 {
     // 请注意,authenticationType 必须与 CookieAuthenticationOptions.AuthenticationType 中定义的相应项匹配
     var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
     // 在此处添加自定义用户声明
     return userIdentity;
 }
Example #2
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;
 }
        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;
        }
Example #4
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;
        }
Example #5
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;
 }
		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;
		}
Example #7
0
 public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<User, string> manager)
 {
     // Îáðàòèòå âíèìàíèå, ÷òî authenticationType äîëæåí ñîâïàäàòü ñ òèïîì, îïðåäåëåííûì â CookieAuthenticationOptions.AuthenticationType
     var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
     // Çäåñü äîáàâüòå óòâåðæäåíèÿ ïîëüçîâàòåëÿ
     return userIdentity;
 }
Example #8
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;
        }
Example #9
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<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 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);
        }
Example #12
0
 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<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;
 }
Example #14
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;
 }
 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<ActionResult> Login(LoginViewModel model)
        {
            // password for jwmcpeak is [email protected]
            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<ApplicationUser> manager,
     string authenticationType)
 {
     var userIdentity = await manager.CreateIdentityAsync(this, authenticationType);
     return userIdentity;
 }
Example #18
0
 public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
 {
     // Обратите внимание, что authenticationType должен совпадать с типом, определенным в CookieAuthenticationOptions.AuthenticationType
     var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
     // Здесь добавьте утверждения пользователя
     return userIdentity;
 }
Example #19
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;
        }
Example #20
0
 public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
 {
     // 注意 authenticationType 必須符合 CookieAuthenticationOptions.AuthenticationType 中定義的項目
     var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
     // 在這裡新增自訂使用者宣告
     return userIdentity;
 }
Example #21
0
            GenerateUserIdentity(UserManager<AppUser> manager)
        {
            var user = await manager
                .CreateIdentityAsync(this, 
                DefaultAuthenticationTypes.ApplicationCookie);

            return user;
        }
        public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<User> manager, string authenticationType)
        {
            var userIdentity = await manager.CreateIdentityAsync(this, authenticationType);

            // Add custom user claims here 

            return userIdentity;
        }
Example #23
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;
 }
 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);
     //Voeg custom claims toe met name de naam en tijdzone van de user
     var claims = new List<Claim>();
     userIdentity.AddClaims(claims);
     return userIdentity;
 }
Example #26
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;
        }
Example #27
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;
        }
Example #28
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;
 }
		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;
		}
Example #30
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;
        }