需要 ASP.NET 中 AddRemoteScheme 的示例实现

n7r*_*der 8 .net c# asp.net authentication f#

我有一个后端应用程序(比如 API-A),它使用我自定义实现的 IAM 解决方案(比如 IAM-I)对传入的请求进行身份验证。本质上,我将请求标头中的几个令牌传递给 IAM-I,IAM-I 处理它们并决定请求是否经过身份验证。

我正在尝试创建一个远程身份验证方案来从 API-A 调用 IAM-I。我如何创建自己的实例AuthenticationBuilder.AddRemoteSchemeMicrosoft.AspNetCore.Authentication.RemoteAuthenticationOptions实现它?

我写过这个:

iServiceCollection
     .AddAuthentication(fun options ->
          options.DefaultScheme          <- JwtBearerDefaults.AuthenticationScheme
          options.DefaultChallengeScheme <- JwtBearerDefaults.AuthenticationScheme)
     .AddRemoteScheme("IAM-I Scheme", "IAM-I", remoteAuthAction)

let remoteAuthAction: Action<RemoteAuthenticationOptions> = new Action<RemoteAuthenticationOptions>(fun options ->
     ................ **TO BE FILLED** .................
);
Run Code Online (Sandbox Code Playgroud)

有人可以帮我弄清楚如何实现RemoteAuthenticationOptions吗?我在网上找不到任何例子。

上面的代码片段是在 F# 中的,但我对 F# 或 C# 都没有问题。

And*_*ndy 0

您的 IAM 解决方案是否使用 JWT 令牌?

JwtBearerDefaults 仅支持 JWT 令牌,如果您的 IAM 解决方案使用 OpenID Connect,那么您应该使用 AddJwtBearer 来保护 API。