OpenIddict 2.0.0 RC3 Final 是否支持 AspNetUsers table?
Does OpenIddict 2.0.0 RC3 Final support AspNetUsers table?
我已按照以下网络链接中的视频教程进行操作,但在导航到 https://localhost:5001/connect/token
时收到以下错误:
fail: Microsoft.AspNetCore.Server.Kestrel[13]
Connection id "0HLFGA04R3IV9", Request id "0HLFGA04R3IV9:00000001": An unhandled exception was thrown by the
application. System.Data.SqlClient.SqlException (0x80131904): Invalid
object name 'OpenIddictApplications'.
据我所知,新的 OpenIdDict 不支持通过迁移创建的 AspNetUsers
table。这是正确的吗?
在本教程中,作者使用的是AspNetUsers
table。注:作者使用的是 OpenIddict 1.0。我正在使用 2.0 RC3。我无法让我的示例 TodoList 项目使用 AspNetusers
table。是否可以让 OpenIddict 2.0 使用 AspNetUsers
table?如果是,如何?
https://www.youtube.com/watch?v=GIQqIz1Gpvo&index=4&list=PLu4Bq53iqJJAo1RF0TY4Q5qCG7n9AqSZf
Startup.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.EntityFrameworkCore;
using TodoListAPI.Data;
using JsonApiDotNetCore.Extensions;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.AspNetCore.Identity;
using OpenIddict.Abstractions;
using OpenIddict.Core;
using OpenIddict.EntityFrameworkCore.Models;
using OpenIddict.Validation;
using TodoListAPI.Models;
using AspNet.Security.OpenIdConnect.Primitives;
using Microsoft.IdentityModel.Tokens;
//// Some code here
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc();
services.AddCors(options =>
{
options.AddPolicy("AllowSpecificOrigins",
builder =>
{
builder.WithOrigins("http://localhost:4200");
});
//options.AddPolicy("AllowAllOrigins",
//builder =>
//{
// builder.AllowAnyOrigin();
//});
});
services.AddDbContext<AppDbContext>(opt =>
{
opt.UseSqlServer(this.GetConnectionString());
opt.UseOpenIddict();
});
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<AppDbContext>()
.AddDefaultTokenProviders();
services.AddOpenIddict()
.AddCore(opt =>
{
opt.UseEntityFrameworkCore()
.UseDbContext<AppDbContext>();
})
.AddServer(options =>
{
options.UseMvc();
options.EnableTokenEndpoint("/connect/token");
options.AllowPasswordFlow();
options.AllowRefreshTokenFlow();
options.DisableHttpsRequirement();
options.AcceptAnonymousClients();
// options.AllowAuthorizationCodeFlow();
})
.AddValidation()
;
services.AddAuthentication(options => {
options.DefaultScheme = OpenIddictValidationDefaults.AuthenticationScheme;
});
services.Configure<IdentityOptions>(options =>
{
options.ClaimsIdentity.UserNameClaimType = OpenIdConnectConstants.Claims.Name;
options.ClaimsIdentity.UserIdClaimType = OpenIdConnectConstants.Claims.Subject;
options.ClaimsIdentity.RoleClaimType = OpenIdConnectConstants.Claims.Role;
});
services.AddJsonApi<AppDbContext>(opt => opt.Namespace = "api/v1");
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
// Shows UseCors with CorsPolicyBuilder.
//app.UseCors(builder => builder.WithOrigins("http://localhost:4200"));
app.UseCors("AllowSpecificOrigins");
//app.UseIdentity();
//app.UseOpenIddict();
//app.useoauth
app.UseAuthentication();
app.UseMvcWithDefaultRoute();
app.UseJsonApi();
}
找到答案:
原来 OpenIddict 需要两组表:ASP 和 OpenIddict 表。
我已按照以下网络链接中的视频教程进行操作,但在导航到 https://localhost:5001/connect/token
时收到以下错误:
fail: Microsoft.AspNetCore.Server.Kestrel[13] Connection id "0HLFGA04R3IV9", Request id "0HLFGA04R3IV9:00000001": An unhandled exception was thrown by the application. System.Data.SqlClient.SqlException (0x80131904): Invalid object name 'OpenIddictApplications'.
据我所知,新的 OpenIdDict 不支持通过迁移创建的 AspNetUsers
table。这是正确的吗?
在本教程中,作者使用的是AspNetUsers
table。注:作者使用的是 OpenIddict 1.0。我正在使用 2.0 RC3。我无法让我的示例 TodoList 项目使用 AspNetusers
table。是否可以让 OpenIddict 2.0 使用 AspNetUsers
table?如果是,如何?
https://www.youtube.com/watch?v=GIQqIz1Gpvo&index=4&list=PLu4Bq53iqJJAo1RF0TY4Q5qCG7n9AqSZf
Startup.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.EntityFrameworkCore;
using TodoListAPI.Data;
using JsonApiDotNetCore.Extensions;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.AspNetCore.Identity;
using OpenIddict.Abstractions;
using OpenIddict.Core;
using OpenIddict.EntityFrameworkCore.Models;
using OpenIddict.Validation;
using TodoListAPI.Models;
using AspNet.Security.OpenIdConnect.Primitives;
using Microsoft.IdentityModel.Tokens;
//// Some code here
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc();
services.AddCors(options =>
{
options.AddPolicy("AllowSpecificOrigins",
builder =>
{
builder.WithOrigins("http://localhost:4200");
});
//options.AddPolicy("AllowAllOrigins",
//builder =>
//{
// builder.AllowAnyOrigin();
//});
});
services.AddDbContext<AppDbContext>(opt =>
{
opt.UseSqlServer(this.GetConnectionString());
opt.UseOpenIddict();
});
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<AppDbContext>()
.AddDefaultTokenProviders();
services.AddOpenIddict()
.AddCore(opt =>
{
opt.UseEntityFrameworkCore()
.UseDbContext<AppDbContext>();
})
.AddServer(options =>
{
options.UseMvc();
options.EnableTokenEndpoint("/connect/token");
options.AllowPasswordFlow();
options.AllowRefreshTokenFlow();
options.DisableHttpsRequirement();
options.AcceptAnonymousClients();
// options.AllowAuthorizationCodeFlow();
})
.AddValidation()
;
services.AddAuthentication(options => {
options.DefaultScheme = OpenIddictValidationDefaults.AuthenticationScheme;
});
services.Configure<IdentityOptions>(options =>
{
options.ClaimsIdentity.UserNameClaimType = OpenIdConnectConstants.Claims.Name;
options.ClaimsIdentity.UserIdClaimType = OpenIdConnectConstants.Claims.Subject;
options.ClaimsIdentity.RoleClaimType = OpenIdConnectConstants.Claims.Role;
});
services.AddJsonApi<AppDbContext>(opt => opt.Namespace = "api/v1");
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
// Shows UseCors with CorsPolicyBuilder.
//app.UseCors(builder => builder.WithOrigins("http://localhost:4200"));
app.UseCors("AllowSpecificOrigins");
//app.UseIdentity();
//app.UseOpenIddict();
//app.useoauth
app.UseAuthentication();
app.UseMvcWithDefaultRoute();
app.UseJsonApi();
}
找到答案:
原来 OpenIddict 需要两组表:ASP 和 OpenIddict 表。