IdentityServer4 并在响应中返回错误

问题描述 投票:0回答:1

我使用 IdentityServer4 作为外部身份提供商。我的前端是一个有角度的 SPA。我在 OnTokenValidated 事件中进行一些自定义令牌验证。在 OnTokenValidated 事件中调用

context.Fail(...)
会导致引发异常/HTTP 500 错误。

在我的 Angular SPA 中,我使用 oidc-client-ts 库。 oidc-client-ts 库有一个“SigninResponse”类型,其中包含 access_token、code、id_token 等,以及一个 error 字段。

https://authts.github.io/oidc-client-ts/classes/SigninResponse.html

这意味着当身份服务器重定向到重定向uri时:

http://url.me/signin-callback?code=...&access_token=...&id_token=...

SigninResponse 由 oidc-client-ts 库解析。

我的问题是如何使我的 OnTokenValidated 事件(或其他?)将“错误”查询参数附加到登录回调重定向:

http://url.me/signin-callback?code=...&access_token=...&id_token=...**&error=myerrormessage**

我想这样做,以便我可以处理我的 Angular SPA 中捕获的错误。

提前致谢!

c# oauth-2.0 oauth identityserver4 oidc-client-ts
1个回答
0
投票

最后我将验证移至

ICustomTokenRequestValidator
。验证现在发生在
ValidateAsync(CustomTokenRequestValidationContext context)
中。设置
context.Result.IsError = true
并填充
context.Result.Error
context.Result.ErrorDescription
会导致 oidc-client-ts 在登录期间抛出错误,我在 SPA 中发现了这一点。这适合我的目的。

不幸的是,我需要做的验证并不像在

OnTokenValidated
事件中那么容易,因为我没有必要的信息(特别是我需要访问“id_token_hint”),所以它确实需要一些“黑客”能够将必要的信息传递给
ICustomTokenRequestValidator

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.