Skip to content

Commit

Permalink
LinkedIn Provider - Added headline, summary, positions and industry (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ericgreenmix authored and TerribleDev committed May 10, 2016
1 parent d47a603 commit e919934
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,22 @@ protected override async Task<AuthenticationTicket> AuthenticateCoreAsync()
context.Identity.AddClaim(new Claim(ClaimTypes.Name, context.Name, XmlSchemaString, Options.AuthenticationType));
context.Identity.AddClaim(new Claim("urn:linkedin:name", context.Name, XmlSchemaString, Options.AuthenticationType));
}
if (!string.IsNullOrEmpty(context.Industry))
{
context.Identity.AddClaim(new Claim("urn:linkedin:industry", context.Industry, XmlSchemaString, Options.AuthenticationType));
}
if (!string.IsNullOrEmpty(context.Positions))
{
context.Identity.AddClaim(new Claim("urn:linkedin:positions", context.Positions, XmlSchemaString, Options.AuthenticationType));
}
if (!string.IsNullOrEmpty(context.Summary))
{
context.Identity.AddClaim(new Claim("urn:linkedin:summary", context.Summary, XmlSchemaString, Options.AuthenticationType));
}
if (!string.IsNullOrEmpty(context.Headline))
{
context.Identity.AddClaim(new Claim("urn:linkedin:headline", context.Headline, XmlSchemaString, Options.AuthenticationType));
}
if (!string.IsNullOrEmpty(context.Link))
{
context.Identity.AddClaim(new Claim("urn:linkedin:url", context.Link, XmlSchemaString, Options.AuthenticationType));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ public LinkedInAuthenticationOptions()
"formatted-name",
"email-address",
"public-profile-url",
"picture-url"
"picture-url",
"industry",
"headline",
"summary",
"positions"
};
BackchannelTimeout = TimeSpan.FromSeconds(60);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.Owin.Security;
using Microsoft.Owin.Security.Provider;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;

namespace Owin.Security.Providers.LinkedIn
{
Expand Down Expand Up @@ -41,6 +42,10 @@ public LinkedInAuthenticatedContext(IOwinContext context, JObject user, string a
Link = TryGetValue(user, "publicProfileUrl");
UserName = TryGetValue(user, "formattedName").Replace(" ", "");
Email = TryGetValue(user, "emailAddress");
Industry = TryGetValue(user, "industry");
Summary = TryGetValue(user, "summary");
Headline = TryGetValue(user, "headline");
Positions = TryGetValueAndSerialize(user, "positions");
}

/// <summary>
Expand Down Expand Up @@ -87,6 +92,28 @@ public LinkedInAuthenticatedContext(IOwinContext context, JObject user, string a
/// </summary>
public string FamilyName { get; private set; }

/// <summary>
/// Describes the users membership profile
/// </summary>
public string Summary { get; private set; }

/// <summary>
/// Industry the member belongs to
/// https://developer.linkedin.com/docs/reference/industry-codes
/// </summary>
public string Industry { get; set; }

/// <summary>
/// The members headline
/// </summary>
public string Headline { get; set; }

/// <summary>
/// Member's current positions
/// https://developer.linkedin.com/docs/fields/positions
/// </summary>
public string Positions { get; set; }

public string Link { get; private set; }

/// <summary>
Expand All @@ -109,5 +136,11 @@ private static string TryGetValue(JObject user, string propertyName)
JToken value;
return user.TryGetValue(propertyName, out value) ? value.ToString() : null;
}

private static string TryGetValueAndSerialize(JObject user, string propertyName)
{
JToken value;
return user.TryGetValue(propertyName, out value) ? JsonConvert.SerializeObject(value) : null;
}
}
}

0 comments on commit e919934

Please sign in to comment.