本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例6: GenerateUserIdentityAsync
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<User, string> manager)
{
// Îáðàòèòå âíèìàíèå, ÷òî authenticationType äîëæåí ñîâïàäàòü ñ òèïîì, îïðåäåëåííûì â CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Çäåñü äîáàâüòå óòâåðæäåíèÿ ïîëüçîâàòåëÿ
return userIdentity;
}
示例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;
}
示例8: GenerateUserIdentityAsync
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ToyAppUser> manager)
{
if (manager == null)
return null;
return await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
}
示例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;
}
示例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);
}
示例11: GenerateUserIdentityAsync
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<UserAccount> manager)
{
// authenticationType が CookieAuthenticationOptions.AuthenticationType で定義されているものと一致している必要があります
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// ここにカスタム ユーザー クレームを追加します
return userIdentity;
}
示例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;
}
示例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;
}
示例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");
}
示例15: GenerateUserIdentityAsync
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(
UserManager<ApplicationUser> manager,
string authenticationType)
{
var userIdentity = await manager.CreateIdentityAsync(this, authenticationType);
return userIdentity;
}