4

私はMVC4のデフォルトのテンプレートを使用しており、独自のopenIDプロバイダー(たとえばhttp://steamcommunity.com/dev)をopenIDログインのリストとユーザーがopenID情報を入力できるopenIDボックスに追加しようとしています。

Googleを追加するには、コメントを外します

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の回答に基づいて、StackExchangeOpenIDを処理するクラスを作成しました。

登録:

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 に答える