4

我正在使用 MVC 4 的默认模板,并尝试将我自己的 openID 提供程序(例如http://steamcommunity.com/dev )添加到 openID 登录列表和一个 openID 框,用户可以在其中输入他们的 openID 信息。

添加谷歌我只是取消评论

OAuthWebSecurity.RegisterGoogleClient();

至于其他自定义解决方案,您可以执行类似的操作

OAuthWebSecurity.RegisterClient(new SteamClient(),"Steam",null);

我遇到的麻烦是创建 SteamClient (或通用的)http://blogs.msdn.com/b/webdev/archive/2012/08/23/plugging-custom-oauth-openid-providers.aspx没有显示在任何地方更改 URL。

4

2 回答 2

7

我想我找不到答案的原因是大多数人认为这是常识。我更喜欢我的感觉不寻常。

public class OidCustomClient : OpenIdClient
{
  public OidCustomClient() : base("Oid", "http://localhost:5004/") { }
}
于 2012-09-27T21:24:39.470 回答
5

根据@Jeff 的回答,我创建了一个类来处理 Stack Exchange OpenID。

登记:

OAuthWebSecurity.RegisterClient(new StackExchangeOpenID());

班级:

public class StackExchangeOpenID : OpenIdClient
{
    public StackExchangeOpenID()
        : base("stackexchange", "https://openid.stackexchange.com")
    {

    }

    protected override Dictionary<string, string> GetExtraData(IAuthenticationResponse response)
    {
        FetchResponse fetchResponse = response.GetExtension<FetchResponse>();

        if (fetchResponse != null)
        {
            var extraData = new Dictionary<string, string>();
            extraData.Add("email", fetchResponse.GetAttributeValue(WellKnownAttributes.Contact.Email));
            extraData.Add("name", fetchResponse.GetAttributeValue(WellKnownAttributes.Name.FullName));
            return extraData;
        }

        return null;
    }
    protected override void OnBeforeSendingAuthenticationRequest(IAuthenticationRequest request)
    {
        var fetchRequest = new FetchRequest();
        fetchRequest.Attributes.AddRequired(WellKnownAttributes.Contact.Email);
        fetchRequest.Attributes.AddRequired(WellKnownAttributes.Name.FullName);
        request.AddExtension(fetchRequest);
    }
}

检索额外数据:

var result = OAuthWebSecurity.VerifyAuthentication();
result.ExtraData["email"];
result.ExtraData["name"];
于 2012-09-29T18:10:55.430 回答