【发布时间】:2022-01-08 10:41:27
【问题描述】:
我将授权代码流与 OpenIddict 库一起使用,我收到“InvalidOperationException”并显示以下消息:“Cannot create DbSet for 'OpenIddictEntityFrameworkCoreApplication' because this type不包含在上下文模型中。”消息。尝试运行应用程序时会抛出此消息。
我在网上找到了一些解决方案,但没有一个能够解决我的问题。
这是我的启动配置和 DbContext。我正在使用 ASPNet Core 6 中的默认身份模型。
Program.cs
builder.Services.AddOpenIddict()
// Register the OpenIddict core components.
.AddCore(options =>
{
// Configure OpenIddict to use the Entity Framework Core stores and models.
// Note: call ReplaceDefaultEntities() to replace the default entities.
options.UseEntityFrameworkCore()
.UseDbContext<ApplicationDbContext>();
})
// Register the OpenIddict server components.
.AddServer(options =>
{
// Enable the client credentials flow.
options.AllowClientCredentialsFlow();
// Enable the authorization code flow.
options.AllowAuthorizationCodeFlow().RequireProofKeyForCodeExchange();
// Enable the token endpoint.
options.SetAuthorizationEndpointUris("/connect/authorize")
.SetTokenEndpointUris("/connect/token");
// Register the signing and encryption credentials.
options.AddDevelopmentEncryptionCertificate()
.AddDevelopmentSigningCertificate();
// Register scopes (permissions)
options.RegisterScopes("api");
// Register the ASP.NET Core host and configure the ASP.NET Core options.
options.UseAspNetCore()
.EnableTokenEndpointPassthrough()
.EnableAuthorizationEndpointPassthrough();
})
// Register the OpenIddict validation components.
.AddValidation(options =>
{
// Import the configuration from the local OpenIddict server instance.
options.UseLocalServer();
// Register the ASP.NET Core host.
options.UseAspNetCore();
});
ApplicationDbContext.cs
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options): base(options) { }
我还没有找到我收到此问题的原因。任何帮助都会很棒。谢谢。
【问题讨论】:
标签: c# authentication oauth-2.0 asp.net-identity openiddict