Custom OpenIdClient for Client URL in MVC 4

I am working with the default template for MVC 4 and trying to add my own openID provider, for example http://steamcommunity.com/dev to the openID list and the openID field in which the user can enter their OpenID information.

To add Google, I just do not comment

OAuthWebSecurity.RegisterGoogleClient(); 

as with other custom solutions, you can do something like

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

I had a problem creating a SteamClient (or generic) http://blogs.msdn.com/b/webdev/archive/2012/08/23/plugging-custom-oauth-openid-providers.aspx not showing up anywhere to change the URL .

+4
source share
2 answers

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

Registration:

 OAuthWebSecurity.RegisterClient(new StackExchangeOpenID()); 

Grade:

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

Getting additional data:

 var result = OAuthWebSecurity.VerifyAuthentication(); result.ExtraData["email"]; result.ExtraData["name"]; 
+5
source

I think the reason I couldn’t find an answer is because most people thought it was common sense. I prefer my meaning to be unusual.

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

Source: https://habr.com/ru/post/1436480/


All Articles