Merge pull request #137 from paullooijmans/master
Implemented customizable profile fields for LinkedIn
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -62,6 +62,20 @@ namespace Owin.Security.Providers.LinkedIn
|
||||
/// </summary>
|
||||
public string ClientSecret { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of profile fields to retrieve when signing in.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 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 <see cref="LinkedInAuthenticatedContext.User"/> property.
|
||||
/// </remarks>
|
||||
public IList<string> ProfileFields { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="ILinkedInAuthenticationProvider" /> used in the authentication events
|
||||
/// </summary>
|
||||
@@ -97,6 +111,16 @@ namespace Owin.Security.Providers.LinkedIn
|
||||
"r_basicprofile",
|
||||
"r_emailaddress"
|
||||
};
|
||||
ProfileFields = new List<string>
|
||||
{
|
||||
"id",
|
||||
"first-name",
|
||||
"last-name",
|
||||
"formatted-name",
|
||||
"email-address",
|
||||
"public-profile-url",
|
||||
"picture-url"
|
||||
};
|
||||
BackchannelTimeout = TimeSpan.FromSeconds(60);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user