diff --git a/Owin.Security.Providers/LinkedIn/LinkedInAuthenticationHandler.cs b/Owin.Security.Providers/LinkedIn/LinkedInAuthenticationHandler.cs index 8ee881b..d68b927 100644 --- a/Owin.Security.Providers/LinkedIn/LinkedInAuthenticationHandler.cs +++ b/Owin.Security.Providers/LinkedIn/LinkedInAuthenticationHandler.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Net.Http; using System.Security.Claims; using System.Threading.Tasks; @@ -17,7 +18,7 @@ namespace Owin.Security.Providers.LinkedIn { private const string XmlSchemaString = "http://www.w3.org/2001/XMLSchema#string"; private const string TokenEndpoint = "https://www.linkedin.com/uas/oauth2/accessToken"; - private const string UserInfoEndpoint = "https://api.linkedin.com/v1/people/~:(id,first-name,last-name,formatted-name,email-address,public-profile-url,picture-url)"; + private const string UserInfoEndpoint = "https://api.linkedin.com/v1/people/"; private readonly ILogger logger; private readonly HttpClient httpClient; @@ -84,7 +85,10 @@ namespace Owin.Security.Providers.LinkedIn string expires = (string) response.expires_in; // Get the LinkedIn user - HttpRequestMessage userRequest = new HttpRequestMessage(HttpMethod.Get, UserInfoEndpoint + "?oauth2_access_token=" + Uri.EscapeDataString(accessToken)); + string userInfoEndpoint = UserInfoEndpoint + + "~:("+ string.Join(",", Options.ProfileFields.Distinct().ToArray()) +")" + + "?oauth2_access_token=" + Uri.EscapeDataString(accessToken); + HttpRequestMessage userRequest = new HttpRequestMessage(HttpMethod.Get, userInfoEndpoint); userRequest.Headers.Add("x-li-format", "json"); HttpResponseMessage graphResponse = await httpClient.SendAsync(userRequest, Request.CallCancelled); graphResponse.EnsureSuccessStatusCode(); diff --git a/Owin.Security.Providers/LinkedIn/LinkedInAuthenticationOptions.cs b/Owin.Security.Providers/LinkedIn/LinkedInAuthenticationOptions.cs index 8b3adf7..0f5ca6c 100644 --- a/Owin.Security.Providers/LinkedIn/LinkedInAuthenticationOptions.cs +++ b/Owin.Security.Providers/LinkedIn/LinkedInAuthenticationOptions.cs @@ -62,6 +62,20 @@ namespace Owin.Security.Providers.LinkedIn /// public string ClientSecret { get; set; } + /// + /// Gets the list of profile fields to retrieve when signing in. + /// + /// + /// See https://developer.linkedin.com/docs/fields/basic-profile for the list of available Basic Profile fields. + /// There are additional member profile fields available, see https://developer.linkedin.com/docs/fields/full-profile. + /// Access to these fields requires that you apply for and are granted access to this information from LinkedIn. + /// + /// The following fields are added to the list by default: id, first-name, last-name, formatted-name ,email-address, public-profile-url, picture-url + /// + /// You can access the returned fields through the property. + /// + public IList ProfileFields { get; private set; } + /// /// Gets or sets the used in the authentication events /// @@ -97,6 +111,16 @@ namespace Owin.Security.Providers.LinkedIn "r_basicprofile", "r_emailaddress" }; + ProfileFields = new List + { + "id", + "first-name", + "last-name", + "formatted-name", + "email-address", + "public-profile-url", + "picture-url" + }; BackchannelTimeout = TimeSpan.FromSeconds(60); } }