Identityserver 4和Azure AD
我正在研究使用Identity Server 4在基于C#的MVC应用程序中进行身份validation。 我想使用存储在Azure AD中的帐户作为有效用户的来源,但文档似乎只是指Google和OpenID,并且仅提及Azure。
有没有人知道如何在与Identity Server 4一起使用Azure AD的过程中使用Azure AD的任何好的文档和/或教程?
您可以使用从IdentityServer登录Azure AD,就像使用例如Javascript或MVC应用程序登录IdentityServer一样。
我最近这样做了,你需要做的就是向Azure广告注册OpenIdConnect选项,如下所示:
public void ConfigureAuth(IAppBuilder app) { app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType); app.UseCookieAuthentication(new CookieAuthenticationOptions()); app.UseOpenIdConnectAuthentication( new OpenIdConnectAuthenticationOptions { ClientId = clientId, Authority = authority, PostLogoutRedirectUri = postLogoutRedirectUri, }); }
有关此更多信息,请访问: https : //docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-devquickstarts-webapp-dotnet
然后,您应该在Login操作中调用ChallengeAsync方法:
var authenticationProperties = new AuthenticationProperties { RedirectUri = "your redirect uri" }; await HttpContext.Authentication.ChallengeAsync(your policy, authenticationProperties);
然后提供一个回调方法作为GET方法,然后按照IdentityServer示例中提供的外部登录示例进行操作: https : //github.com/IdentityServer/IdentityServer4.Samples/blob/dev/Quickstarts/4_ImplicitFlowAuthenticationWithExternal/src/QuickstartIdentityServer/Quickstart/Account/ AccountController.cs
在github上有一个Azure AD示例 ,它来自IdentityServer示例中提供的外部登录示例。
该示例还修复了一个已知问题“中间件生成的状态参数对于Azure AD#978来说太大了”