【发布时间】:2020-10-16 22:22:08
【问题描述】:
API 详细信息:.Net Core 3.1 REST API 使用 IdentityServer4 版本 3.1.3
我有许多以指定格式发送响应的 API。
例如注册端点返回以下响应:
{
"responseCode": 0,
"developerMessage": "Response code not specified.",
"clientMessage": null,
"data": {"id":123},
"exception": null
}
我使用 IdentityServer4 开发了身份验证服务器。 但是,我的令牌端点返回以下响应:
{
"access_token": "eyJhbGciOiJSUzI1NiIsImtpZCI6Ik...",
"expires_in": 1209600,
"token_type": "Bearer",
"refresh_token": "1u8_VOFHTaeqWEWd6R...",
"scope": "offline_access api1"
}
现在的要求是 API 的所有端点都应该以相同的格式返回响应。
这意味着我需要更改令牌(或更多)端点的响应。
我查看了ICustomTokenResponseGenerator 服务(提到了here),但它所做的只是在响应中添加更多字段。 它来自 IdentityServer3
class CustomTokenResponseGenerator : ICustomTokenResponseGenerator
{
public Task<TokenResponse> GenerateAsync(ValidatedTokenRequest request, TokenResponse response)
{
response.Custom.Add("custom_field", "custom data");
return Task.FromResult(response);
}
}
但是,我想完全改变响应。
我可以使用任何其他服务来获得以下响应吗?
{
"responseCode": 0,
"developerMessage": "Response code not specified.",
"clientMessage": null,
"data":
{
"access_token": "eyJhbGciOiJSUzI1NiIsImtpZCI6Ik...",
"expires_in": 1209600,
"token_type": "Bearer",
"refresh_token": "1u8_VOFHTaeqWEWd6R...",
"scope": "offline_access api1"
},
"exception": null
}
【问题讨论】:
标签: asp.net-core authentication oauth identityserver4 openid