我创建了一个安全令牌服务(STS),一个引用STS的服务和一个示例桌面应用程序.
当使用Windows身份验证和Message安全性时,这可以正常工作,从STS检索令牌并成功调用服务方法.该服务返回一个包含当前用户标识的字符串,该标识符返回我的AD用户名.
但是我要求对数据库而不是AD进行身份验证.我试过创建一个CustomUserNameValidator(在STS中,这是正确的位置吗?)并在web.config中引用它.然后,我提供如下所示的凭据.
SampleServiceReference.SampleServiceClient client = new SampleServiceReference.SampleServiceClient();
client.ClientCredentials.UserName.UserName
= "alex";
client.ClientCredentials.UserName.Password
= "pass";
我相信证书设置正确(全部使用'localhost'),但是在调用服务时我收到以下异常:
System.ServiceModel.FaultException:ID3242:无法对安全令牌进行身份验证或授权.
无论我尝试什么似乎都失败了.我所描述的甚至可能吗?服务客户端是否也将客户端凭据传递给STS,或者我完全误解了这里发生的事情?
这个stackoverflow问题是类似的,但我已经检查了受众URL,似乎没问题.WIF STS ID3242
有没有人对如何在使用STS时实现自定义身份验证有任何建议?
在修复此处描述的问题时,我创建了另一个我可以在网络上的其他任何地方找到的内容:
SignInResponseMessage message = WSFederationMessage.CreateFromFormPost(context.Request) as SignInResponseMessage;
Run Code Online (Sandbox Code Playgroud)
上面的代码不断调用IsValidRequestString(),这会导致无限循环.每次调用都是相同的,堆栈如下所示:
> TestIdentityBroker.dll!TestIdentityBroker.Service.WsFederationRequestValidator.IsValidRequestString(System.Web.HttpContext context, string value, System.Web.Util.RequestValidationSource requestValidationSource, string collectionKey, out int validationFailureIndex) Line 19 C#
[External Code]
TestIdentityBroker.dll!TestIdentityBroker.Service.WsFederationRequestValidator.IsValidRequestString(System.Web.HttpContext context, string value, System.Web.Util.RequestValidationSource requestValidationSource, string collectionKey, out int validationFailureIndex) Line 19 + 0x21 bytes C#
[External Code]
TestIdentityBroker.dll!TestIdentityBroker.Service.WsFederationRequestValidator.IsValidRequestString(System.Web.HttpContext context, string value, System.Web.Util.RequestValidationSource requestValidationSource, string collectionKey, out int validationFailureIndex) Line 19 + 0x21 bytes C#
[External Code]
TestIdentityBroker.dll!TestIdentityBroker.Service.WsFederationRequestValidator.IsValidRequestString(System.Web.HttpContext context, string value, System.Web.Util.RequestValidationSource requestValidationSource, string collectionKey, out int validationFailureIndex) Line 19 + 0x21 …Run Code Online (Sandbox Code Playgroud) asp.net-mvc identity wif sts-securitytokenservice asp.net-mvc-3
我看到FedMetadata文档可以提供注销通知和订阅端点,web.config定义了登录请求的发布者URL,但我无法找到WIF知道发送注销请求的位置.如果我使用的STS为登录和签出请求定义了不同的端点,我如何在代码中访问它或在web.config中设置它?
在研究ACS时,发现了这个官方ACS演示http://www.fabrikamshipping.com/.
在应用程序本身,当使用其中一个提供程序(我选择Google)登录时,我可以在浏览器历史记录中看到包含从ACS返回的声明的URL.这是以以下内容开头的网址:
即使清除了所有浏览器缓存和cookie,转到此URL也会将我登录到应用程序中.
因此,如果我从某台公共计算机登录该应用程序,然后注销,则会通过浏览器历史记录中的此URL显示我的帐户.
我知道这是ACS身份处理工作的标准方式.
我在这里错过了什么?
我正在使用WindowsIdentity来获取当前用户的ID以进行SSO.在大多数情况下,我得到了我想要的,但对于一些用户,我得到了奇怪的结果.示例代码:
IIdentity WinId = HttpContext.Current.User.Identity;
WindowsIdentity wi = (WindowsIdentity)WinId;
String idName = wi.Name.Replace(@"TESTHQ\", "");
Run Code Online (Sandbox Code Playgroud)
有时我会得到duy@test.org,然后我就可以登录了.其他时候我得到了@ test.org/broadcast @ test.org.
有没有可以使用Windows 7查看当前身份的地方?喜欢在控制面板或什么?
谢谢!
我的ASP.Net应用程序的几页使用WIF直接连接到另一个服务.WIF只是在这里取得进展,虽然它安装在测试和生产服务器上,但每当新的程序员或测试人员获得最新版本并碰巧在他们的机器上没有安装WIF运行时的情况下点击这些页面时,他就会获得YSOD和关于找不到Microsoft.IdentityModel的错误...他们从未阅读过,而是触发IM告诉我我的应用程序已损坏.
我想检测是否已安装WIF运行时并显示每条有用的错误消息,如果没有则链接到下载页面.我不想检查特定的.dll路径,因为这可能会改变......并且3.5和4.0已经有不同的路径.
有没有最好的方法来检测是否安装了WIF运行时?
(显然在一个没有引用它的页面中......如果没有安装它将无法正确显示)
编辑
看起来WIF包含在4.5的框架中,因此3.5/4.0的特定方法可以.没有必要面向未来.
因为我是WIF的新手.我想在WIF上创建自定义STS,但这些文档仅适用于.net 3.5:http: //msdn.microsoft.com/en-us/library/ee748498.aspx ,我在vs 2012中找不到这些模板.所以我该怎么做?任何人都可以向我提供一些信息吗?谢谢 !
我使用federatedauthentication在客户端和wcf服务应用程序之间进行通信时遇到问题.
在我的客户端应用程序(带有Forms身份验证的ASP.NET MVC)上,我将用户数据传递给声明,并构建一个SessionSecurityToken:
SessionSecurityToken sessionSecurityToken = new
SessionSecurityToken(transformedPrincipal,
TimeSpan.FromMinutes(tokenLifeTime));
sessionSecurityToken.IsReferenceMode = true;
FederatedAuthentication.SessionAuthenticationModule.WriteSessionTokenToCookie(sessionSecurityToken);
Run Code Online (Sandbox Code Playgroud)
tokenLifeTime等于25分钟.
在我的服务上,我想阅读cookie并获取存储在声明中的用户数据.但是,当我在我的服务上运行以下代码时:
SessionSecurityToken token;
FederatedAuthentication.SessionAuthenticationModule.TryReadSessionTokenFromCookie(out token);
Run Code Online (Sandbox Code Playgroud)
令牌为空.
更新:
我注意到,如果我只是在客户端应用程序中创建一个服务,则会毫无问题地读取令牌.我也可以设置Httpcontext.Current.user,它工作正常.但是我确实希望通过服务引用来使用服务,在这种情况下,HttpContext.Current.User都是空的(但不是null!),并且上面没有读取cookie.
我试图以编程方式生成microsoft.identityModel配置中包含的以下配置.
<federatedAuthentication>
<wsFederation passiveRedirectEnabled="false" requireHttps="true" issuer="https://IssuedByFoo.com" realm="http://Foo.com/" />
<cookieHandler requireSsl="true" path="/" />
</federatedAuthentication>
Run Code Online (Sandbox Code Playgroud)
到目前为止,我还没能成功配置它.我尝试在application_Start中设置以下内容,但在尝试联合时收到错误消息
"ID5002:FederatedPassiveSignIn控件上的Issuer属性必须设置为可以处理WS-Federation被动协议消息的STS端点的地址."
FederatedAuthentication.WSFederationAuthenticationModule.Realm = "http://Foo.com/";
FederatedAuthentication.WSFederationAuthenticationModule.Issuer = "https://IssuedByFoo.com";
FederatedAuthentication.WSFederationAuthenticationModule.PassiveRedirectEnabled = false;
FederatedAuthentication.WSFederationAuthenticationModule.RequireHttps = true;
FederatedAuthentication.SessionAuthenticationModule.CookieHandler.RequireSsl = true;
FederatedAuthentication.SessionAuthenticationModule.CookieHandler.Path = "/";
Run Code Online (Sandbox Code Playgroud)
我很确定我没有正确配置FederatedAuthentication,我不确定在哪里正确配置它.我注意到的一件事是,当我在开始请求上设置断点并检查FederatedAuthentication.WSFederationAuthenticationModule时,当web.config中没有值时,我看不到设置的属性.
我在构建时不断收到此错误:
无法识别的配置节system.identityModel
我在配置中添加了以下内容:
<system.identityModel>
<identityConfiguration>
<audienceUris>
<add value="TEST"/>
</audienceUris>
<issuerNameRegistry type="System.IdentityModel.Tokens.ConfigurationBasedIssuerNameRegistry, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<trustedIssuers>
<add thumbprint="1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234" name="YourSTSName"/>
</trustedIssuers>
</issuerNameRegistry>
<certificateValidation certificateValidationMode="None"/>
</identityConfiguration>
</system.identityModel>
Run Code Online (Sandbox Code Playgroud)
我正在使用.Net 4.6