我已经在下面的网络链接上学习了视频教程,当我导航到
https://localhost:5001/connect/token
:
失败:microsoft.aspnetcore.server.kestrel[13]
连接ID“0hlfga04r3iv9”,请求ID“0hlfga04r3iv9:0000000 1”:由
应用程序。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
启动.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();
}