【发布时间】:2018-12-30 11:20:49
【问题描述】:
我已按照以下网络链接中的视频教程进行操作,当我导航到 https://localhost:5001/connect/token 时收到以下错误:
失败:Microsoft.AspNetCore.Server.Kestrel[13] Connection id "0HLFGA04R3IV9", Request id "0HLFGA04R3IV9:00000001": 一个未处理的异常被抛出 应用。 System.Data.SqlClient.SqlException (0x80131904):无效 对象名称“OpenIddictApplications”。
据我所知,新的 OpenIdDict 不支持使用迁移创建的 AspNetUsers 表。这是正确的吗?
在本教程中,作者使用的是AspNetUsers 表。注意:作者使用的是 OpenIddict 1.0。我正在使用 2.0 RC3。我无法让我的示例 TodoList 项目使用 AspNetusers 表。是否可以让 OpenIddict 2.0 使用 AspNetUsers 表?如果是,怎么做?
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();
}
【问题讨论】:
标签: asp.net-web-api asp.net-core openiddict