我的项目正在使用 asp.net 成员资格(不是身份(,我正在尝试根据此链接中列出的步骤实现OAuth
在测试代码时,它在我的数据库中创建了标识表(AspNetUsers,AspNetUserRoles,AspNetRoles...(
我不想使用这些表,我想将其与成员表一起使用(aspnet_Users,aspnet_Membership...
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
var applicationUserManager = context.OwinContext.GetUserManager<ApplicationUserManager>();
//while executing this line, the identity tables are created
var applicationUser = await applicationUserManager.FindAsync(context.UserName, context.Password);
if (applicationUser == null)
{
context.SetError("invalid_grant", "The user name or password is incorrect.");
return;
}
var claimsIdentityOAuth =
await applicationUser.GenerateUserIdentityAsync(applicationUserManager,
OAuthDefaults.AuthenticationType);
var claimsIdentityCookie = await applicationUser.GenerateUserIdentityAsync(applicationUserManager,
CookieAuthenticationDefaults.AuthenticationType);
var properties = CreateProperties(applicationUser.UserName);
var authenticationTicket = new AuthenticationTicket(claimsIdentityOAuth, properties);
context.Validated(authenticationTicket);
context.Request.Context.Authentication.SignIn(claimsIdentityCookie);
}
如何使用具有 asp.net 会员资格的OAuth?
您可以这样做,但是,您需要Identity
表的自定义实现,然后使用Entity Framework Code First
为所需的表创建映射
ASP.NET 标识的自定义存储提供程序
protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<IdentityUser>().ToTable("YouUserTableMembership");
modelBuilder.Entity<ApplicationUser>().ToTable("YouUserTableMembership");
modelBuilder.Entity<IdentityRole>().ToTable("role");
modelBuilder.Entity<IdentityUserRole>().ToTable("YouUserRoleTableMembership");
modelBuilder.Entity<IdentityUserClaim>().ToTable("YouUserClaimTableMembership");
modelBuilder.Entity<IdentityUserLogin>().ToTable("YouUserLoginTableMembership");
}