Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for LinkedIn #29

Closed
abjerner opened this issue Jun 18, 2015 · 5 comments
Closed

Add support for LinkedIn #29

abjerner opened this issue Jun 18, 2015 · 5 comments

Comments

@abjerner
Copy link
Owner

I have some code lying around for this, that I need to finish and clean up a bit. This is probably something that will be added after the release of v1.0.

@makdff
Copy link

makdff commented Aug 4, 2015

Hi. When are you able to release your v.1.0 of Skybrud with implementation of linkedin authentification support?

@abjerner
Copy link
Owner Author

abjerner commented Aug 4, 2015

LinkedIn is currently not an area of focus, since I'm working on improving the implementation for the services already supported instead.

I don't really have a time frame for when v1.0 will be released since I primarily work on this project in my spare time. An optimistic guess is that v1.0 will be out in a couple of months, but LinkedIn support is something that will be introduced after this release.

But as I wrote in my previous comment, I do have some unfinished code for LinkedIn. I will try to find some time to wrap this a bit, and push the code to GitHub ;)

@abjerner
Copy link
Owner Author

@makdff I have now added a new project to the solution called Skybrud.Social.LinkedIn. I have uploaded this due to requests by a few users, but it will not be officially supported until at least after v1.0, meaning that I wont have the time to document or answer questions.

Anyways, this little snippet might help you out with then authentication using OAuth 2.0:

@using Skybrud.Social.LinkedIn.OAuth2

@model MvcApplication1.Models.TestPage

@{
    ViewBag.Title = "Index";
}

@{

    // Handle input
    string action = Request.QueryString["do"];
    string code = Request.QueryString["code"];
    string state = Request.QueryString["state"];

    // Initialize the OAuth client
    LinkedInOAuthClient oauth = new LinkedInOAuthClient {
        ApiKey = "",
        ApiSecret = "",
        RedirectUri = Model.BaseUrl
    };

    if (action == "login") {

        // Redirect the user to the authentication page at LinkedIn.com
        Response.Redirect(oauth.GetAuthorizationUrl("bacon", "r_basicprofile"));

    } else if (!String.IsNullOrWhiteSpace(code)) {

        LinkedInAccessTokenResponse token = oauth.GetAccessTokenFromAuthCode(code);
        oauth.AccessToken = token.AccessToken;

        DateTime expiresAt = DateTime.Now.AddSeconds(token.ExpiresIn.TotalSeconds);

        <table>
            <tr>
                <td style="font-size: 10px; font-weight: bold; text-transform: uppercase; padding-right: 25px;">Expires in</td>
                <td style="font-size: 12px;">
                    @token.ExpiresIn.TotalSeconds
                    (~@token.ExpiresIn.TotalDays days &bull; @expiresAt.ToString("r"))
                </td>
            </tr>
            <tr>
                <td style="font-size: 10px; font-weight: bold; text-transform: uppercase; padding-right: 25px;">Access Token</td>
                <td style="font-size: 12px;">
                    @token.AccessToken
                </td>
            </tr>
        </table>

        <br />

        <a href="@Model.BaseUrl?do=login" class="button">Login again</a>

    } else if (Request.QueryString["error"] != null) {

        <p><b>@Request.QueryString["error"]</b><br />@Request.QueryString["error_description"]</p>

        <a href="@Model.BaseUrl?do=login" class="button">Login with LinkedIn</a>

    } else {

        <a href="@Model.BaseUrl?do=login" class="button">Login with LinkedIn</a>

    }

}

@makdff
Copy link

makdff commented Aug 12, 2015

@abjerner Great thanks :)

@abjerner
Copy link
Owner Author

abjerner commented Nov 7, 2015

I haven't really updated any of the code, but the LinkedIn implementation now has it's own repository, so you can follow the progress here:

https://github.com/abjerner/Skybrud.Social.LinkedIn

Eventually the LinkedIn project will also be released as it's own NuGet package, although I don't really have a time frame for this.

@abjerner abjerner closed this as completed Nov 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants