【发布时间】:2022-01-27 03:15:36
【问题描述】:
请在下面找到我为生成引用令牌而不是 JWT 而应用的步骤:
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