Azure AD 回调不会转到 AuthenticateExternalAsync 方法

Azure AD callback is not going to AuthenticateExternalAsync method

我正在使用 OpenID Connect 连接到 Azure ID,我可以在 Azure 中成功进行身份验证并将请求返回到 OpenID Azure AD 配置中指定的重定向 uri。

app.UseOpenIdConnectAuthentication( new OpenIdConnectAuthenticationOptions { AuthenticationType = " TEST", Caption = "Test Azure AD", SignInAsAuthenticationType = signInAsType, ClientId = "<client ID>", Authority = "https://sts.windows.net/<tenantId>", ResponseType = OpenIdConnectResponseTypes.CodeIdToken, RedirectUri = "https://localhost:44392/External/Login", This is another webapi project, not identityserver host. AuthenticationMode = AuthenticationMode.Passive, });

身份验证成功后,它使用代码 IdToken 重定向回 https://localhost:44392/External/Login

问题:

  1. 它不会像 google-signin 那样在重定向时停在 AuthenticateExternalAsync 方法吗?

  2. 我是否必须解码 IdToken JWT 才能获得用户声明?

  3. 在重定向方法中,如何从 IdSrv3 生成 Access Token 以授权其他 webapis?
  4. 用户能否同时拥有本地登录和多个外部登录(Azure AD、Google 等)。在这种情况下,SSO 如何与 IDsrv3 一起使用?

  5. 是否有实施外部登录的 IdSrv3 示例?最好是 Azure AD ?

我刚刚经历了这个过程,所以我会尽力回答以帮助 you/others。如果我误解了你的问题,请原谅我。

  1. AuthenticateExternalAsync 应该调用,但您需要将 AzureAd return 连接到 IDS(身份服务器)而不是您的应用程序。您的流程应该类似于:app -> IDS -> AzureAd -> IDS (AuthenticateExternalAsync) -> App.

  2. AuthenticateExternalAsync 中,您会得到 ExternalAuthenticationContext.ExternalIdentity,其中包含声明 - 无需解码 JWT 令牌。

  3. 一旦您 return 在 AuthenticateExternalAsync 中成功 AuthenticatedResult,IDS 就会处理这个问题,例如 context.AuthenticateResult = new AuthenticateResult("UserId", name, claims);

  4. 是的。您可以出于 SSO 目的强制使用 登录方法,否则我想 IDS 会处理它 post first-login.

  5. 我找到了 this helpful (runs through setup of IDS and AzureAd), but it does use the old Azure Portal rather than the new one. They don't seem to have any samples in their gallery

希望能有所帮助:)