【发布时间】:2022-08-18 03:40:33
【问题描述】:
我已经下载了 eShopOnContainers 这是一个.NET 微服务示例参考应用程序用于微服务架构和 Docker 容器。
https://github.com/dotnet-architecture/eShopOnContainers
我认为这非常好,但我想停用使用IdentityServer4 的Identity.API,并且以后可能会使用Duende IdentityServer。目前我们使用 Azure AD B2C,我想继续使用它。目前这意味着不需要本地令牌生成。
查看Ordering.API - Startup.cs 它使用以下authentication:
public static IServiceCollection AddCustomAuthentication(this IServiceCollection services, IConfiguration configuration)
{
// prevent from mapping \"sub\" claim to nameidentifier.
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Remove(\"sub\");
var identityUrl = configuration.GetValue<string>(\"IdentityUrl\");
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = AspNetCore.Authentication.JwtBearer.JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = AspNetCore.Authentication.JwtBearer.JwtBearerDefaults.AuthenticationScheme;
}).AddJwtBearer(options =>
{
options.Authority = identityUrl;
options.RequireHttpsMetadata = false;
options.Audience = \"orders\";
});
return services;
}
在 AD B2C 中,我有一个具有两个不同范围的应用程序,并且我已经能够获得具有这两个范围的访问令牌。但是,将上面的代码与访问令牌一起使用时,当用于新的ASP.NET Core Web API 时,我只会得到 HTTP 401 Unauthorized。我还尝试仅设置options.MetadataAddress 和options.Audience,但使用下面的指南没有运气,HTTP 401 Unauthorized 的结果相同。
https://dzimchuk.net/setting-up-your-asp-net-core-2-0-apps-and-services-for-azure-ad-b2c/
代币:
我可以使用默认的 Microsoft 身份平台身份验证使其工作,但我不想将客户端密码添加到每个微服务中。
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApi(builder.Configuration.GetSection(\"AzureAd\"));
我知道 Ocelot 之前被用作 API 网关,但由于对 WebSocket 协议的内置支持而被更改为 Envoy,这是在 eShopOnContainers 中实现的新 gRPC 服务间通信所必需的。一旦我得到令牌工作,我需要在那里改变什么吗?
标签: c# .net asp.net-core microservices identityserver4