Identityserver3 - HybridFlow 不返回配置文件范围

Identityserver3 - HybridFlow not returning profile scope

我已经使用 this 教程设置了 identityserver3 和 MVC4 客户端。当我将客户端配置为使用 'Implicit' 流程时,一切都按预期工作,我正在返回 'profile' 范围。即我可以找到声明 first_name 和 given_name。下面是我的配置代码。

客户端和用户配置

public static class Users
{
    public static List<InMemoryUser> Get()
    {
        return new List<InMemoryUser>
        {
            new InMemoryUser
            {
                Username = "Bob",Password = "password",Subject = "1",
                Claims = new []
                {
                    new Claim(Constants.ClaimTypes.GivenName,"firstName"),
                    new Claim(Constants.ClaimTypes.FamilyName,"lastName")
                }
            }
        };
    }
}

public static class Clients
{
    public static IEnumerable<Client> Get()
    {
        return new[] 
        {
            new Client
            { 
                ClientId = "MVC",
                ClientName = "MVC Client Name",
                RedirectUris = new List<string>
                {
                    "https://localhost:44302/"
                },
                Flow = Flows.Implicit,
                AllowAccessToAllScopes = true
            }
        };
    }
}

身份服务器配置

public void Configuration(IAppBuilder app)
{
    JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<string, string>();

    app.Map("/identity", appBuilder => {
    appBuilder.UseIdentityServer(new IdentityServer3.Core.Configuration.IdentityServerOptions
    {
        SiteName = "Site Name",
        SigningCertificate = LoadCertificate(),
        RequireSsl = false,
        Factory = new IdentityServer3.Core.Configuration.IdentityServerServiceFactory()
            .UseInMemoryClients(Clients.Get())
            .UseInMemoryUsers(Users.Get())
            .UseInMemoryScopes(StandardScopes.All)
        });
    });

    app.UseCookieAuthentication(new Microsoft.Owin.Security.Cookies.CookieAuthenticationOptions
    {
        AuthenticationType = "Cookies"
    });

    app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
    {
        Authority = "https://localhost:44302/identity",
        ClientId = "MVC",
        RedirectUri = "https://localhost:44302/",
        ResponseType = "id_token",                
        SignInAsAuthenticationType = "Cookies",
        Scope = "openid profile"
    });
}

在我的 MVC 应用程序中,我在名为 'Contact'

的主控制器上保护了 Action
[Authorize]
public ActionResult Contact()
{            
    ClaimsPrincipal principal = User as ClaimsPrincipal;
    return View(principal.Claims);
}

最后是简单的视图

@model IEnumerable<System.Security.Claims.Claim>
@foreach (var item in Model)
{
    <div>
        <span>@item.Type</span>
        <span>@item.Value</span>
    </div>
}
</div>

现在,当我 运行 这个应用程序时,在单击安全 'Contact' link 后,我被重定向到 STS 服务器,在提供凭据后,我可以看到下面的输出。

请注意,声明 given_namefamily_name存在于STS返回的claims中

问题:

我更改客户端以支持混合流的那一刻。我 没有收到 退回索赔 given_namefamily_name

我对代码进行了以下更改。

客户端配置

 public static IEnumerable<Client> Get()
    {
        return new[] 
        {
            new Client
            { 
                ClientId = "MVC",
                ClientName = "MVC Client Name",
                RedirectUris = new List<string>
                {
                    "https://localhost:44302/"
                },
                Flow = Flows.Hybrid,//Changed this to Hybrid
                AllowAccessToAllScopes = true
            }
        };
    }

服务器配置

app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
        {
            Authority = "https://localhost:44302/identity",
            ClientId = "MVC",
            RedirectUri = "https://localhost:44302/",
            ResponseType = "code id_token token",  //Changed response type              
            SignInAsAuthenticationType = "Cookies",
            Scope = "openid profile"
        });

在 运行ning 申请后,我可以看到 STS 返回的以下声明

请注意,声明 given_namefamily_name这次不见了

我错过了什么吗?

当您只请求 id_token 时,用户的所有声明都在 id_token 中。当您更改获取令牌的请求(通过请求代码或令牌)时,只有配置为 "AlwaysInclude" 的用户声明才会包含在 id_token 中。其余部分必须使用您收到的 access_token 从用户信息端点检索。您可以使用 IdentityModel 库中的帮助程序 API 轻松访问用户信息端点。我们的示例展示了如何做到这一点:https://github.com/IdentityServer/IdentityServer3.Samples/blob/master/source/Clients/MVC%20OWIN%20Client%20(Hybrid)/Startup.cs#L66