当前位置: 首页 > 编程语言 > C#

Identityserver4和AzureAD共享

时间:2023-04-10 14:01:22 C#

Identityserver4和AzureAD我正在使用IdentityServer4在基于C#的MVC应用程序中进行身份验证。我想使用存储在AzureAD中的帐户作为有效用户的来源,但文档似乎只提到了Google和OpenID,并且只提到了Azure。有谁知道关于如何将AzureAD与IdentityServer4一起使用的任何好的文档和/或教程?您可以从IdentityServer登录到AzureAD,就像您使用例如登录到IdentityServer一样。Javascript或MVC应用程序。我最近这样做了,您需要做的就是像这样向AzureAD注册OpenIdConnect选项:publicvoidConfigureAuth(IAppBuilderapp){app.UseCookieAuthentication(newCookieAuthenticationOptions());app.UseOpenIdConnectAuthentication(newOpenIdConnectAuthenticationOptions{ClientId=clientId,Authority=authority,PostLogoutRedirectUri=postLogoutRedirectUri,});}有关此的更多信息:https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-devquickstarts-webapp-dotnet然后,您应该在登录操作中调用ChallengeAsync方法:varauthenticationProperties=newAuthenticationProperties{RedirectUri="你的重定向uri"};等待HttpContext.Authentication.ChallengeAsync(你的策略,authenticationProperties);然后提供回调方法作为GET方法,然后按照IdentityServer示例中提供的外部登录示例:https://github.com/IdentityServer/IdentityServer4.Samples/blob/dev/Quickstarts/4_ImplicitFlowAuthenticationWithExternal/src/QuicksstartIdentityServer/Quickstart/Account/AccountController.csgithub上有一个AzureAD示例,该示例取自IdentityServer示例中提供的外部登录示例此示例还修复了一个已知问题“中间件生成的状态参数对Azure无效AD#978It'stoobig”以上就是C#学习教程:Identityserver4和AzureAD分享的全部内容,如果对你有用,需要进一步了解C#学习教程,希望大家多多关注—本文收集自网络,不代表立场,如涉及侵权,请点击右边联系管理员删除,如需转载请注明出处: