4

I'm working with the default template for MVC 4 and trying to add my own openID provider for example http://steamcommunity.com/dev to the list of openID logins and an openID box where the user can type in their openID information.

To add Google I just un-comment

OAuthWebSecurity.RegisterGoogleClient();

as for other custom solutions you can do something like

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

The trouble I have is creating SteamClient (or a generic one) http://blogs.msdn.com/b/webdev/archive/2012/08/23/plugging-custom-oauth-openid-providers.aspx doesn't show anywhere to change the URL.

2 Answers 2

7

I think the reason I could not find the answer is that most people thought it was common sense. I prefer my sense to be uncommon.

public class OidCustomClient : OpenIdClient
{
  public OidCustomClient() : base("Oid", "http://localhost:5004/") { }
}
5

Based on @Jeff's answer I created a class to handle Stack Exchange OpenID.

Register:

OAuthWebSecurity.RegisterClient(new StackExchangeOpenID());

Class:

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);
    }
}

Retrieving extra data:

var result = OAuthWebSecurity.VerifyAuthentication();
result.ExtraData["email"];
result.ExtraData["name"];
1
  • I just tried this and found one issue: every time user logs in, they see google permission page. With original RegisterGoogleClient(), users see it only once. Any thoughts?
    – kennethc
    Commented May 25, 2014 at 20:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.