如何将自定义错误消息返回到 Keycloak (3.4.3) 中自定义 spnego 身份验证器中的前端?



>我正在Keycloak中构建一个自定义身份验证器,它不仅将用户登录到keycloaks SSO实例,而且还通过休息调用登录到旧版(SAP(系统中。

现在,我从此旧版API收到错误消息,并且我想在通过自定义身份验证器登录时向最终用户显示消息(由callee-param国际化(,但是我还不知道该怎么做。

我认为这与例如 github 上的 spnego 身份验证器的以下行有关:

...
else {
context.getEvent().error(Errors.INVALID_USER_CREDENTIALS);
context.failure(AuthenticationFlowError.INVALID_CREDENTIALS);
}
...

当将 .error((-value 更改为"test!"时,会记录此值,但向用户显示的错误也是无效的凭据行。 因此,AuthenticationFlowError 似乎是一个 ENUM,我认为它不适用于来自第三方的动态国际化消息。但是有没有办法告诉我的身份验证上下文从我的第三方系统返回错误消息?

任何帮助都非常感谢

所以,看看钥匙斗篷源代码(开源ftw!我刚刚发现了如何做到这一点:

代替上面的行,可以这样做:

else {
//errorresponse from restcall to thirdparty-api (just removing prefix here)
responseString = responseString.replace("sap_error_", "");
//actually I try to do a somewhat silent idplogin, so this might fit. 
//you can change this error to the errormsg from thirdparty, too,
// so its collected in the logs error=-part.
context.getEvent().error(Errors.IDENTITY_PROVIDER_ERROR);
//here we're building the actual responseHandler.
//One might even want to set the status to status from thirdparty. 
Response challengeResponse = context.form().setError(responseString)
.createErrorPage(Response.Status.INTERNAL_SERVER_ERROR);
//And in the end we apply the failureChallenge to the Context  
context.failureChallenge(AuthenticationFlowError.IDENTITY_PROVIDER_ERROR,
challengeResponse);
}

我注释了代码以明确执行的操作。

编辑:由于这个问题刚刚获得了赞成票:请保重!.setError((-content必须<255个字符,否则你会得到一个异常(DB-Field太短iirc,测试到keycloak 7(。

此致敬意 多米尼克

最新更新