vis*_* os 6 identityserver3 identityserver4
I\xe2\x80\x99ve 需要在 Identity Server 令牌端点的令牌响应中添加自定义成员。
\n预期响应示例:
\n{\n"access_token": "XXXXXXXXXXXXXXX",\n"token_type": "bearer",\n"expires_in": 3600,\n"scope": "patient/Observation.read patient/Patient.read",\n"patient": 123,\n"refresh_token":"XXXXXXXXXXXXXXXXX"\n}\n
Run Code Online (Sandbox Code Playgroud)\n我想在响应中添加范围、患者参数,即使它存在于访问令牌中。
\n任何关于这方面的指导都会非常有帮助!
\n对于 Identity Server 4,您可以通过实现 ICustomTokenRequestValidator 接口在令牌响应中添加自定义参数。
public class CustomTokenRequestValidator : ICustomTokenRequestValidator
{
public Task ValidateAsync(CustomTokenRequestValidationContext context)
{
context.Result.CustomResponse =
new Dictionary<string, object> {{ "patient", "alice"}};
return Task.CompletedTask;
}
public CustomTokenRequestValidator()
{
}
}
Run Code Online (Sandbox Code Playgroud)
另外不要忘记在启动时在configureServices方法中注册依赖项。您可以在添加 IdentityServer 服务后附加 .AddCustomTokenRequestValidator<>({pass-in-name-of-class-implementing})。
归档时间: |
|
查看次数: |
2006 次 |
最近记录: |