简体   繁体   English

用户身份验证失败时,如何从基于WIF的自定义安全令牌中返回错误代码和消息?

[英]How to return error code & message from the custom WIF based SecurityTokenService when user authentication fails?

I am building my custom Security Token Service inheriting from the Windows Identity Foundation's SecurityTokenService . 我正在构建继承自Windows Identity Foundation的SecurityTokenService的自定义安全令牌服务。

However, I do not find any appropriate method which I can use to inform client application about the authentication failure details when authentication fails. 但是,我找不到任何可以用来在身份验证失败时通知客户端应用程序有关身份验证失败详细信息的适当方法。

In case of WIF based custom STS, how to inform client about authentication failure and the reason (error code/message) of the failure? 对于基于WIF的自定义STS,如何通知客户端认证失败以及失败的原因(错误代码/消息)? There is no method which returns boolean True or False. 没有方法返回boolean True或False。

I can throw some exception, but is it a recommended way? 我可以抛出一些异常,但这是推荐的方法吗?

It seems clients always expect some Claims in the object STS returns. 看来客户总是希望在STS返回的对象中有一些Claims。 But when authentication is failed, how come there will be any Claim? 但是,如果身份验证失败,怎么会有索赔? Or which Claims to return when authentication is failed? 还是身份验证失败时返回哪些声明?

I went through many WIF related samples available on various forums, but nothing helped me to answer my queries. 我浏览了各种论坛上提供的许多与WIF相关的示例,但是没有什么可以帮助我回答我的问题。

It's not the right thing to return some Claims of the user who is not authenticated ! 返回未经身份验证的用户的某些声明是不正确的! Claims are not meant for this purpose. 声明并非用于此目的。 So returning some claim (which tells about authentication failure) is not the solution. 因此,返回某些声明(说明身份验证失败)不是解决方案。

About 500 status code: 大约500个状态代码:

When error is reported by the WCF service using Fault Contract/Exception, 500 is the default HTTP status code used. 当WCF服务使用Fault Contract / Exception报告错误时,将使用默认的HTTP状态代码500。 So if you see the 500 status code, it's not an error; 因此,如果看到500状态代码,那不是错误; it's expected. 这是预期的。

Having said this, you can change the status code by writing your custom service behavior and the class which implements IErrorHandler . 话虽如此,您可以通过编写自定义服务行为和实现IErrorHandler的类来更改状态代码。

Refer to this post . 参考这篇文章 It gave me these inputs. 它给了我这些意见。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM