是的,这是一个合理的方法来解决这个问题。其实我认为 StackOverflow做同样的事情。不使用OpenID的人们的自定义用户数据库也将在openid.service.com上,所以实际上他们也会在这种情况下使用OpenID,尽管他们不知道它。
有一点要注意的是在您的例子openid.service.com将不能够断言,从谷歌和其他原声明的标识符,因为二级的RP将不会从你的中介接受的说法,因为它有对那些声称的ID没有权力。相反,你可以做的是在你的openid.service.com和你的每个辅助RP之间进行一次no-authentication OpenID。是的,OpenID实际上有一个流程,其中没有声明标识符从OP传递到仅限RP的扩展。因此,您可以使用DotNetOpenAuth FetchRequest
和FetchResponse
分机来请求您的辅助RP和您的中央服务之间用户的实际claims_id。而辅助RP必须小心谨慎地接受来自中央RP的断言。
这里的辅助RP之间的代码的草图和您的中心之一:从openid.service.com
OpenIdRelyingParty rp;
var request = rp.CreateRequest("https://openid.service.com/");
request.IsExtensionOnly = true;
var fetchRequest = new FetchRequest();
fetchRequest.Attributes.AddRequired("http://openid.service.com/useridentity");
request.AddExtension(fetchRequest);
request.RedirectToProvider();
步骤2的用户RP请求认证:openid.service
步骤1。 COM,作为OP,接收请求(作为一个OP是一个巨大的repsonsibility ......这是由所有帐户的一个非常不完整的样本。您应该参考OpenIdProvider samples that are available。)
OpenIdProvider op;
IRequest request = op.GetRequest();
/// ...
IAnonymousRequest anonRequest = request as IAnonymousRequest;
if (anonRequest != null) {
// The key part for this sample snippet is that you make sure the RP asking
// is one of your own, since you're not following the typical OpenID flow.
if (!IsWhiteListedRealm(hostRequest.Realm)) {
anonRequest.IsApproved = false; // reject all RPs that aren't in the whitelist
} else {
// Perhaps here is where you'll start your double role as an RP
// to authenticate the user if there isn't already a FormsAuth cookie.
}
}
return op.PrepareResponse(request).AsActionResult()
步骤3:辅助RP收到来自您的代理OpenID服务的响应。
OpenIdRelyingParty rp;
var response = rp.GetResponse();
if (response != null) {
if (response.Provider.Uri.Authority != "openid.service.com") {
throw new Exception(); // only assertions from our own OP are trusted.
}
if (response.Status == AuthenticationStatus.ExtensionsOnly) {
var fetchResponse = response.GetExtension<FetchResponse>();
string claimedId = fetchResponse.GetAttributeValue("http://openid.service.com/useridentity");
FormsAuthentication.RedirectFromLoginPage(claimedId);
}
}
这些样品无法完成。上述内容并不适用于填补这些角色的网站的许多常规安全缓解措施。这仅仅是一个草图,概述了您的应用在特定情况下应采取的一些额外步骤。
非常感谢您对我的问题和输入的检查!你的片段会非常方便! – 2013-03-24 21:36:16
还有一件事情我不完全清楚 - 所以我将使用OpenID作为协议,它通过扩展将某种用户标识传递给RP。我必须为此实施全面的OP吗? (有发现机制等,就像在样本中...) – 2013-03-26 23:15:44
好问题。由于你的OP永远不会声明一个声明的ID,你不需要从样本中设置user.aspx。但是您确实需要一个OP标识符,它是样本中OP主页返回的XRDS文档。 – 2013-03-27 02:26:52