首页 > 解决方案 > 在 ASP.NET Core 中,为什么 AddOpenIdConnect 没有 AuthorizationEndpoint 作为选项,就像 AddoAuth 一样?

问题描述

OIDC 所需的授权端点。然而,AddOpenIDConnect 没有 AddOAuth 的 AuthorizationEndpoint 选项。

标签: asp.net-coreoauth-2.0openid-connect

解决方案


OpenID Connect 处理程序通常使用特殊的“发现”端点来查找授权端点(除其他外)。它需要您的授权并将“/.well-known/openid-configuration”附加到它以获取元数据。

从那里它authorization_endpoint从 JSON 中获取。

例如,将权限设置为https://login.microsoftonline.com/common/v2.0(Azure AD) 将从https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration获取元数据。

{
  "authorization_endpoint":"https://login.microsoftonline.com/common/oauth2/v2.0/authorize"
}

请注意,这是处理程序在默认情况下以最少的配置执行的操作。您可以手动设置MetadataAddress而不是设置发现端点 URL。Authority如果您根本不想使用发现端点,您可以Configuration手动提供该属性:

o.Configuration = new Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectConfiguration
{
    // Other properties omitted
    AuthorizationEndpoint = ""
};

推荐阅读