当前位置: 首页>>代码示例>>C#>>正文


C# UserManager.CreateIdentityAsync方法代码示例

本文整理汇总了C#中UserManager.CreateIdentityAsync方法的典型用法代码示例。如果您正苦于以下问题:C# UserManager.CreateIdentityAsync方法的具体用法?C# UserManager.CreateIdentityAsync怎么用?C# UserManager.CreateIdentityAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UserManager的用法示例。


在下文中一共展示了UserManager.CreateIdentityAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenerateUserIdentityAsync

 public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
 {
     // 请注意,authenticationType 必须与 CookieAuthenticationOptions.AuthenticationType 中定义的相应项匹配
     var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
     // 在此处添加自定义用户声明
     return userIdentity;
 }
开发者ID:AntonHuang,项目名称:WebAppEF6,代码行数:7,代码来源:IdentityModels.cs

示例2: GenerateUserIdentityAsync

        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;
        }
开发者ID:jornfilho,项目名称:identity-2.1,代码行数:27,代码来源:ApplicationUser.cs

示例3: GenerateUserIdentityAsync

        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;
        }
开发者ID:Beterer,项目名称:tnLabs,代码行数:30,代码来源:ApplicationUser.cs

示例4: GenerateUserIdentityAsync

 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;
 }
开发者ID:sadiqna,项目名称:TicketDesk,代码行数:7,代码来源:TicketDeskUser.cs

示例5: GenerateUserIdentityAsync

		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;
		}
开发者ID:xfischer,项目名称:MvcGestionAsso,代码行数:7,代码来源:ApplicationUser.cs

示例6: GenerateUserIdentityAsync

 public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<User, string> manager)
 {
     // Îáðàòèòå âíèìàíèå, ÷òî authenticationType äîëæåí ñîâïàäàòü ñ òèïîì, îïðåäåëåííûì â CookieAuthenticationOptions.AuthenticationType
     var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
     // Çäåñü äîáàâüòå óòâåðæäåíèÿ ïîëüçîâàòåëÿ
     return userIdentity;
 }
开发者ID:densem-2013,项目名称:ACSDining,代码行数:7,代码来源:User.cs

示例7: GenerateUserIdentityAsync

        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;
        }
开发者ID:Tmaturano,项目名称:PetSuite,代码行数:28,代码来源:ApplicationUser.cs

示例8: GenerateUserIdentityAsync

        public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ToyAppUser> manager)
        {
            if (manager == null)
                return null;

            return await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
        }
开发者ID:VicZhang1,项目名称:ToyApp,代码行数:7,代码来源:ToyAppUser.cs

示例9: GenerateUserIdentityAsync

 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;
 }
开发者ID:MdotIvanov,项目名称:TravelWithMe,代码行数:7,代码来源:TravelWithMeUser.cs

示例10: GrantResourceOwnerCredentials

        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);
        }
开发者ID:NicoVerbeeke,项目名称:BackEndZomer2015,代码行数:33,代码来源:SimpleAuthorizationServerProvider.cs

示例11: GenerateUserIdentityAsync

 public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<UserAccount> manager)
 {
     // authenticationType が CookieAuthenticationOptions.AuthenticationType で定義されているものと一致している必要があります
     var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
     // ここにカスタム ユーザー クレームを追加します
     return userIdentity;
 }
开发者ID:kyasbal-1994,项目名称:linophi,代码行数:7,代码来源:UserAccount.cs

示例12: GenerateUserIdentityAsync

 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;
 }
开发者ID:gonzalogilrepositorio,项目名称:Proyecto-ComIT,代码行数:7,代码来源:User.cs

示例13: GenerateUserIdentityAsync

 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;
 }
开发者ID:cwschroeder,项目名称:MeterTestComService,代码行数:7,代码来源:IdentityModels.cs

示例14: Login

        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");
        }
开发者ID:jwmcpeak,项目名称:gettingstartedwithmvc5,代码行数:25,代码来源:AccountController.cs

示例15: GenerateUserIdentityAsync

 public async Task<ClaimsIdentity> GenerateUserIdentityAsync(
     UserManager<ApplicationUser> manager,
     string authenticationType)
 {
     var userIdentity = await manager.CreateIdentityAsync(this, authenticationType);
     return userIdentity;
 }
开发者ID:WS-and-Cloud,项目名称:BookShopSystem,代码行数:7,代码来源:ApplicationUser.cs


注:本文中的UserManager.CreateIdentityAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。