2022 年 11 月之后,身份服务器 4 将不再维护,因此从逻辑上讲,我们希望放弃这一点。我一直在寻找替代方案,但似乎没有太多。我们不想选择 Duende 来逃避许可证,AAD 也是如此。为单个 Kubernetes 解决方案推出自己的身份服务有意义吗?
编辑:也许问题本身没有明确说明。我知道可以推出我自己的“身份解决方案”,但是,我不知道这的含义。我想知道是否有任何其他免费或开源解决方案可以用来实现这一目标。如果没有,我们自己做起来会有多困难?我也没有找到太多关于从头开始执行此操作的信息。
我将我的 Asp.net core Blazor WebAssembly 应用程序更新为 .net 6。一切都很好,但是从 github 操作进行的部署不起作用并抛出此错误:
...
Copying file: 'Microsoft.AspNetCore.ApiAuthorization.IdentityServer.dll'
Copying file: 'Microsoft.AspNetCore.Authentication.JwtBearer.dll'
Omitting next output lines...
Error: EISDIR: illegal operation on a directory, open '/home/site/wwwroot/wwwroot/Identity/lib/bootstrap/LICENSE'
An error has occurred during web site deployment.
Kudu Sync failed
\n/opt/Kudu/Scripts/starter.sh "/home/site/deployments/tools/deploy.sh"
Error: Failed to deploy web package to App Service.
Error: Deployment Failed with Error: Package deployment using ZIP Deploy failed. Refer logs for more details.
Run Code Online (Sandbox Code Playgroud)
这里可能有什么问题?
编辑/解决方案:
以前许可证文件的路径是:/home/site/wwwroot/wwwroot/Identity/lib/bootstrap/LICENSE/LICENSE …
我需要编写需要ConfigureServices完全执行的业务逻辑。
OnTokenValidated本身的位置很糟糕ConfigureServices。
中间件的替代方案是什么
AddOpenIdConnect,以便我可以Success完全灵活地调用以使用注入的服务?
services.AddAuthentication(options =>
{
options.DefaultScheme = "cookie";
//...
})
.AddOpenIdConnect("oidc", options =>
{
options.Authority = "https://localhost:5001";
/....
options.Scope.Add("offline_access");
options.Events.OnTokenValidated = async n =>
{
//Need other services which will only
//get injected once ConfigureServices method has fully executed.
};
}
Run Code Online (Sandbox Code Playgroud)
所以。我使用 ASP.NET Core 模型和 Angular使用 Visual Studio Pro 2019 (v16.11.9) 创建了一个全新的项目。我将身份验证选项设置为“个人用户帐户”。
我得到了一个使用Angular 8、ASP.NET Core 3.1(没有深入研究为什么这些版本,只是接受了事实)、Entity Framework和Identity 的工作脚手架项目,这正是我想要的,除了框架版本。我想使用最新的Angular 13和ASP.NET Core 6.0。
所以我开始逐个版本升级我的 Angular 版本,检查每一步应用程序是否仍然有效。到了 Angular 13,没有发现问题,身份验证工作正常。
然后,我按照非常复杂(此处具有讽刺意味)的 Microsoft 教程来更新您的 .NET Core 版本:从 ASP.NET Core 3.1 迁移到 6.0并更新.csproj。和繁荣,当我尝试访问应用程序受身份验证保护的部分时,我收到以下错误:

InvalidOperationException: The default Identity UI layout requires a partial view '_LoginPartial' usually located at '/Pages/_LoginPartial' or at '/Views/Shared/_LoginPartial' to work. Based on …Run Code Online (Sandbox Code Playgroud) asp.net-mvc-scaffolding asp.net-identity asp.net-core duende-identity-server angular13
我已经将基于 Identity Server 的项目从原始的 Identity Server 4 升级到Duende 的 Identity Server 6。升级似乎有效,但我必须删除一些现有代码才能使其正常工作。
这是我们以前的配置Startup.cs
services.AddIdentityServer()
.AddOperationalStore(options => {
options.RedisConnectionString = Configuration.GetConnectionString("Redis");
options.Db = 1;
})
.AddRedisCaching(options => {
options.RedisConnectionString = Configuration.GetConnectionString("Redis");
options.KeyPrefix = "custom_prefix";
})
.AddSigningCredential(new X509Certificate2(Path.Combine(HostingEnvironment.WebRootPath, "secretauth.pfx"), "secret_key"))
.AddUserStore() // Custom User Store
.AddResourceStore<CustomResourceStore>()
.AddClientStore<CustomClientStore>();
Run Code Online (Sandbox Code Playgroud)
之前的版本使用了IdentityServer4.Contrib.RedisStore,从 Identity Server 6 开始我们不再可用。
这意味着我们的新实现没有为会话数据添加 Redis 缓存的选项,而且我看不到可能提供该功能的 Duende 相关 nuget 包。
留给我们的只有这个;
services.AddIdentityServer(options =>
{
options.LicenseKey = Configuration.GetValue<string>(key: "Duende.IdentityServer:licenseKey");
})
.AddUserStore() // Custom User Store
.AddClientStore<CustomClientStore>()
.AddResourceStore<CustomResourceStore>();
Run Code Online (Sandbox Code Playgroud)
我是否在某个地方缺少一个可能有用的 Nuget …
当我尝试对 duende 身份 6 使用手动密钥管理时,我收到从 api“无法访问已处置对象。对象名称:'RSA'”返回的错误。当我尝试从代码创建 RSA 参数时,它确实有效,但是它不适用于私钥和公钥。
请告诉我下面的代码有什么问题。另外,如果有人能告诉我除此之外的任何其他方法。
Program.cs 中的代码
// this will return signing credentials
SigningCredentials GetSigningCredentials()
{
var p = @"MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAKj/nCpvB71XiFgH
3ykjGU/8SutC680yQjqQdEGh/SDxPAncW5SfavcFSt0K/1UuyyXNc5o9RIcns2rE
4W49T0T4VIP4WhVkAQEvBc4NeLX+o9W3pj6A3dNb+M+2VzZGcFPRtkypNtgxsNJ8
s0b4pmGP9zeMzCkd3UJgCLlZOdz/AgMBAAECgYAzHUywkPB4VjdI2OioWpNXW+mV
CqKjZ6YcbICdMU+MXSpZmSqh4y3JFPK1tJPRwdtzzZY/enR1pI5hprbATw7gQUK1
1SxRIhyC70DSuX6C4dSLQBnXCUzcWokY1IB+iyftHamrtVdTK2IBS7Q9iMAUX49o
XcmDsn8vbAze6mg4YQJBAOCPDcELQtZeZAhEp7Zy4Ks2MGt3YASoDySPrJxCRn5x
WvBynmS+pDbptY7bnV9tk9pIBfxXgooUwbjqGT5WoTcCQQDAqRYhYFtk+8l8Yjmo
Fhr859U6wnjhq9BCzwtRVzPfkpYjOUeHaEJozEUtAKN2y68Aq9zNDdq6SL+9QIcP
MqZ5AkAYsAF+GKPXd3c6Cno5t7V1fTajifM3b9aCWX1LjIm9eu7ZgnBheQgKtXTt
aL2LcTuRAtwNmv1R+ug1UR9HWDTPAkAJHDXCsEbCGLHnYtGtJBZ0nRXVKHsE2NYJ
QrcbSo9WZB0bX0sFmSWCxR4EScJxDKKi2n2faKdOJcCDV3jLfC6pAkBSn5HYh1Wm
ycOUmv6MANXgrmUnmhD23hAMQeJmU4Rs6mzVXCwlJUO3EvgkONjtOUh6NFM9G2gJ
Y1AmxhQIrusw";
var privateKey = p.ToByteArray();
using RSA rsa = RSA.Create();
RSAParameters rsaKeyInfo = rsa.ExportParameters(false);
rsa.ImportPkcs8PrivateKey(privateKey, out _);
var signingCredentials = new SigningCredentials(new RsaSecurityKey(rsa), SecurityAlgorithms.RsaSha256)
{
CryptoProviderFactory = new CryptoProviderFactory { CacheSignatureProviders = false }
};
return signingCredentials;
}
builder.Services.AddIdentityServer(options =>
{
options.LicenseKey =
"xyz"; …Run Code Online (Sandbox Code Playgroud) 我有一些集成测试,它们使用针对 ConfigurationDbContext 的真实数据库。升级到 Duende IdentityServer 6.0 时,由于添加了 DbContext 连接池功能,ConfigurationDbContext 的构造函数会中断(仅接受 1 个参数而不是 2 个)。
这段代码破坏了:
public static ConfigurationDbContext GetConfigurationDbContext()
{
var connectionString = Configuration.GetConnectionString("ConfigurationDbContext");
var builder = new DbContextOptionsBuilder<ConfigurationDbContext>();
builder.UseSqlServer(connectionString);
var options = new ConfigurationStoreOptions
{
DefaultSchema = Schema.IdSrv
};
return new ConfigurationDbContext(builder.Options, options);
}
Run Code Online (Sandbox Code Playgroud)
所以我把它改为:
return new ConfigurationDbContext(builder.Options);
Run Code Online (Sandbox Code Playgroud)
现在我可以构建,但我的测试因以下错误而失败:
Unable to resolve service for type 'Duende.IdentityServer.EntityFramework.Options.ConfigurationStoreOptions'
我应该如何传递 ConfigurationStoreOptions ?查看Github上的代码,看起来依赖于依赖注入。(从服务集合中获取选项)。
所以我一直在 Net7 预览版中工作,并一直在尝试部署一个具有身份和身份验证功能的 WASM 项目,该项目在本地运行良好。当我部署网站 500 秒并深入研究一些日志时,我得到:
2022-11-07T13:42:28.854805951Z fail: Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler[3]
2022-11-07T13:42:28.854856853Z Exception occurred while processing message.
2022-11-07T13:42:28.854865053Z System.NullReferenceException: Object reference not set to an instance of an object.
2022-11-07T13:42:28.856255318Z at Microsoft.AspNetCore.ApiAuthorization.IdentityServer.IdentityServerJwtBearerOptionsConfiguration.ResolveAuthorityAndKeysAsync(MessageReceivedContext messageReceivedContext)
2022-11-07T13:42:28.856286120Z at Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.HandleAuthenticateAsync()
Run Code Online (Sandbox Code Playgroud)
在我的 Program.cs 中我有
builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(connectionString));
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
builder.Services.AddDefaultIdentity<ApplicationUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<ApplicationDbContext>();
builder.Services.AddIdentityServer()
.AddApiAuthorization<ApplicationUser, ApplicationDbContext>();
builder.Services.AddAuthentication()
.AddIdentityServerJwt()
.AddJwtBearer()
.AddGoogle(googleOptions =>
{
googleOptions.ClientId = builder.Configuration["Authentication:Google:ClientId"];
googleOptions.ClientSecret = builder.Configuration["Authentication:Google:ClientSecret"];
});
builder.Services.AddControllersWithViews();
builder.Services.AddRazorPages();
builder.Services.AddHttpContextAccessor();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{ …Run Code Online (Sandbox Code Playgroud) identity azure blazor-webassembly duende-identity-server .net-7.0