使用声明的标识符检索身份验证提供程序类型

时间:2012-12-27 16:03:01

标签: c# asp.net asp.net-mvc openid dotnetopenauth

我浏览了 DotNetOpenAuth 上的文档,但找不到基于ClaimedIdentifier检索身份验证提供程序类型的方法。我正在寻找类似于以下方法的方法:

ProviderType providerType = ClaimedIdentifier.Parse(" .... ").Type;

是否有检索提供者类型的方法?

查询DotNetOpenAuth以检索此信息,而不是在应用程序中维护状态变量或将类型作为查询字符串参数传递,这非常棒。虽然,看起来这可能是必要的......

2 个答案:

答案 0 :(得分:1)

我试图找到类似的东西,以确定返回的提供者,但到目前为止,我刚刚做了类似的事情,response.Provider.Uri.ToString()。包含(“yahoo”),对于雅虎。如果有更好的东西会有所帮助,这似乎很俗气,但它是我现在唯一可以使用的东西。

答案 1 :(得分:1)

请勿解析声明的标识符以尝试找出提供者。虽然这可能适用于常见情况,但有些情况会导致失败,您也可能会因为攻击而打开自己。

您从IAuthenticationRequest的实例获取ClaimedIdentifier。此接口还具有Provider属性,该属性返回IProviderEndpoint实例,其上包含Uri属性。这个Uri属性是您应该如何识别您特别感兴趣的提供商。例如:

public void Login(string userSuppliedIdentiifer, OpenIdRelyingParty rp) {
    IAuthenticationRequest request = rp.CreateRequest(userSuppliedIdentifier;
    if (request != null) {
        if (request.Provider.Uri == new Uri("https://www.google.com/o8/ud")) {
            // It's Google!
        } else if (request.Provider.Uri == new Uri("https://me.yahoo.com/whatever-it-is")) {
            // It's Yahoo!
        }

        request.RedirectToProvider();
    }
}

我希望这会有所帮助。