Identityserver 4和Azure AD

Pat*_*ckA 24 c# azure-active-directory identityserver4

我正在研究使用Identity Server 4在基于C#的MVC应用程序中进行身份验证.我想使用存储在Azure AD中的帐户作为有效用户的来源,但文档似乎只是指Google和OpenID,并且仅提及Azure.

有没有人知道在与Identity Server 4一起使用Azure AD的过程中如何使用Azure AD的任何好的文档和/或教程?

Esp*_*dbø 13

您可以使用从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,
        });
}
Run Code Online (Sandbox Code Playgroud)

有关这方面的更多信息: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);
Run Code Online (Sandbox Code Playgroud)

然后提供一个回调方法作为GET方法,然后按照IdentityServer示例中提供的外部登录示例进行操作:https://github.com/IdentityServer/IdentityServer4.Samples/blob/dev/Quickstarts/4_ImplicitFlowAuthenticationWithExternal/src/QuickstartIdentityServer/Quickstart/Account/ AccountController.cs

  • 这就是OpenID Connect的关键所在; 您将处理密码的麻烦委托给另一个系统,在本例中为Microsoft.您必须添加login.microsoft.com或类似的权限,然后在重定向时使用.OpenID Connect不是Microsoft特定的; 它只是一个规范,说明如何进行第三方提供商的登录. (2认同)

MiF*_*vil 7

在github上有一个Azure AD示例,它来自IdentityServer示例中提供的外部登录示例.

该示例还修复了一个已知问题"中间件生成的状态参数对于Azure AD#978来说太大了"

  • https://github.com/aspnet/Security/issues/1310上面给出的代码示例现已过时,来自Haok的评论"旧的1.0身份验证堆栈不再起作用,并且在2.0中已经过时".这特别涉及IdentityServer startup.cs的Config/cookie身份验证的上述repo集的方式.迁移是在6月17日左右完成的,我能说清楚. (3认同)