首页 > 解决方案 > Identity Server 4 外部提供者声明扩展

问题描述

我在 ASP.NET Core 应用程序中有身份服务器 4 配置。除了打开和配置文件范围外,我还希望将登录用户的生日作为声明。我对以下配置没有运气

services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme)
                .AddFacebook(options =>
                {
                    options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
                    options.AppId = "XXX";
                    options.AppSecret = "XXX";
                    options.SaveTokens = true;
                    options.Scope.Add("user_birthday");
                    options.Fields.Add("birthday");
                })

知道为什么这不起作用吗?

OIDC 客户端请求配置

var config = {
    authority: "https://localhost:44330",
    client_id: "ff-client",
    redirect_uri: "https://localhost:5003/callback.html",
    response_type: "id_token token",
    scope:"openid profile gateway identity",
    post_logout_redirect_uri: "https://localhost:5003/index.html",
    acr_values: "idp:Facebook",
    loadUserInfo: true,
};

标签: asp.net-coreidentityserver4facebook-oauth

解决方案


检查用户是否授予访问权限。参考:https ://developers.facebook.com/docs/graph-api/using-graph-api/common-scenarios/#how-to-get-an-access-token

如果您想确认用户已授予您的应用 user_birthday 权限,您可以在 /{user-id}/permissions 边缘执行 GET 操作。假设用户授予权限,API 响应如下所示:

样本响应

{
  "data": [
    {
      "permission":"user_birthday",
      "status":"granted"
    }
  ]
}

推荐阅读