【问题标题】:Generating Reference Token Instead of JWT生成引用令牌而不是 JWT
【发布时间】:2022-01-27 03:15:36
【问题描述】:

请在下面找到我为生成引用令牌而不是 JWT 而应用的步骤:

  1. 在 [Clients] 表中,我更新了属性 [AccessTokenType] = 1。请注意,这是配置为从 Angular 前端应用程序使用的客户端。

OIDC 客户端配置(Angular 应用)

"IdentityGuardsConfig": {
"oidcSettings": {
  "authority": "http://localhost:5000",
  "client_id": "local_spa",
  "redirect_uri": "http://localhost:4200/#/identity-guards/auth-callback#",
  "post_logout_redirect_uri": "http://localhost:4200",
  "response_type": "id_token token",
  "scope": "openid profile inspection_profile",
  "filterProtocolClaims": true,
  "loadUserInfo": true,
  "automaticSilentRenew": true,
  "silent_redirect_uri": "http://localhost:4200/#/identity-guards/silent-refresh#"
},

2- 由于 API (/connect/introspect) 是安全的,我必须创建 API 资源和 API 机密(根据 thread)。同样根据线程,我必须分配前端客户端请求的确切范围(3 个范围 ==> 打开、配置文件、检查配置文件)

应用上述配置后,IdentityServer 服务返回引用令牌,并且引用令牌被持久化在 [PersistedGrants] 表中

为了验证引用令牌,我可以通过从 Postman 中点击 (/connect/introspect) API 来做到这一点(下面是转换后的 cURL 请求)

curl --location --request POST 'http://localhost:5000/connect/introspect' \
--header 'Authorization: Basic bG9jYWxfc3BhOlBAc3N3MHJk' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'token=f007eff8fc2a3d8d9af7cb605b93b78d7004880d24356acebf928dae5a48dd8e'

以下是我收到的上述 cURL 请求的响应:

{
"iss": "http://localhost:5000",
"nbf": 1640694748,
"exp": 1640698348,
"aud": "http://localhost:5000/resources",
"client_id": "local_spa",
"sub": "f6a5ccec-9d70-4c7c-ab50-7a932f685cac",
"auth_time": 1640694748,
"idp": "local",
"amr": "pwd",
"email": "admin@isp.com",
"name": "admin@isp.com",
"given_name": "admin",
"phone_number": "0506198339",
"role": "SystemAdmin",
"preferred_username": "admin@isp.com",
"active": true,
"scope": "openid profile inspection_profile"
}

但是,当我尝试访问 (/.well-known/openid-configuration) 时,出现以下异常:

处理请求时发生未处理的异常。 例外:发现使用相同名称的身份范围和 API 范围。这是无效的配置。对身份范围和 API 范围使用不同的名称。找到的范围:openid、profile、inspection_profile IResourceStoreExtensions.cs 中的 IdentityServer4.Stores.IResourceStoreExtensions.Validate(IEnumerable identity, IEnumerable apiResources),第 60 行

【问题讨论】:

    标签: asp.net-core jwt identityserver4 identityserver3 dotnetopenauth


    【解决方案1】:

    我认为错误消息很好地解释了问题所在。

    找到使用相同名称的身份范围和 API 范围。这是一个无效的配置。为身份范围和 API 范围使用不同的名称。

    您需要确保 IdentityResourceApiScope 名称不相同。

    【讨论】:

    • 然后,如果我从 ApiScope 中删除 [openid profile Inspection_profile] 范围,则 (/connect/introspect) 端点将无法工作,因为最初在生成参考令牌时,它请求了前 3 个范围。所以我在这里遗漏了一些东西?
    • 在这里查看我的答案,stackoverflow.com/questions/63811157/… APIScope 不应包含“openid profile 或 introspection_profile”,它们仅用于 IdentityResources。
    【解决方案2】:

    @Tore Nestenius 你是对的。作为建议,我将 [inspection_profile] 范围从 [IdentityResources] 移至 [ApiResources]。 此外,对于我在 [IdentityClaims] 中已有的所有自定义声明,我将它们重新链接到 [openid] 个人资料。

    【讨论】:

      猜你喜欢
      • 2018-08-29
      • 2021-07-29
      • 2018-02-01
      • 1970-01-01
      • 2017-04-06
      • 2020-09-28
      • 1970-01-01
      • 2019-11-29
      • 2018-10-18
      相关资源
      最近更新 更多