Identityserver 4和Azure AD

时间:2017-02-01 10:59:03

标签: c# azure-active-directory identityserver4

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

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

2 个答案:

答案 0 :(得分:12)

您可以使用从IdentityServer对Azure AD进行登录,就像使用从IdentityServer登录IdentityServer一样。一个Javascript或MVC应用程序。

我最近已经这样做了,您需要做的就是向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

答案 1 :(得分:7)

sample with Azure AD on github中有一个IdentityServer samples,来自"State parameter generated by middleware is too large for Azure AD #978"中提供的外部登录示例。

该示例还修复了一个已知问题{{3}}