我正在为 SSO 设置开发 OpenId 提供程序 - 它基本上是一个 Web 应用程序门户,与用户有权访问的任何“应用程序”共享凭据。我设置了提供程序,一切正常,但我有一个关于安全性的问题。
我想在 Provider 向 RP 发送肯定断言之前对其进行一些权限检查;即用户实际上对发出请求的应用程序具有权限。
这是我目前得到的 Provider 代码(只是一个片段,如果需要可以添加更多):
private bool AutoRespondIfPossible(out ActionResult response)
{
if (ProviderEndpoint.PendingRequest.IsReturnUrlDiscoverable(OpenIdProvider.Channel.WebRequestHandler) == RelyingPartyDiscoveryResult.Success
&& User.Identity.IsAuthenticated && this.RealmIsValid(ProviderEndpoint.PendingAuthenticationRequest.Realm)) {
if (ProviderEndpoint.PendingAuthenticationRequest != null) {
if (ProviderEndpoint.PendingAuthenticationRequest.IsDirectedIdentity
|| this.UserControlsIdentifier(ProviderEndpoint.PendingAuthenticationRequest)) {
ProviderEndpoint.PendingAuthenticationRequest.IsAuthenticated = true;
response = this.SendAssertion();
return true;
}
}
//we don't want anon requests
if (ProviderEndpoint.PendingAnonymousRequest != null) {
ProviderEndpoint.PendingAnonymousRequest.IsApproved = false;
response = this.SendAssertion();
return true;
}
}
response = null;
return false;
}
基本上我正在做的是验证请求的领域(在RealmIsValid
方法中)与我的可接受主机名列表中的主机名匹配,然后我根据主机名比较用户权限。
我想知道的是:准确度如何ProviderEndpoint.PendingAuthenticationRequest.Realm
?如果我理解正确,领域是由依赖方设置的 - 端点是否有可能从该请求中指定的领域以外的 URI 接收请求?或者我可以安全地假设领域总是准确的(即:匹配依赖方的 URI)?