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

Working with LinkedIn #35

Closed
taudep opened this issue Aug 1, 2013 · 12 comments

Comments

@taudep
Copy link

commented Aug 1, 2013

I'm creating an example to work with LinkedIn. I'm getting pretty close, but it's still not working. I get the authorized_handler called with an appropriate access_token, but then when I go to actually make an API call, it fails.

Here's some of the critical code, I have a demo file setup almost identically to the github.py demo:

linkedin = oauth.remote_app(
    'linkedin',
    consumer_key='KEY',
    consumer_secret='SECRET',
    base_url='https://api.linkedin.com/v1/',
    request_token_url=None,
    request_token_params={'scope': 'r_fullprofile', 'state': 'PUT_SOME_CSR_PROTECTION_HERE'},
    access_token_method='POST',
    access_token_url='https://www.linkedin.com/uas/oauth2/accessToken',
    authorize_url='https://www.linkedin.com/uas/oauth2/authorization',
) 

My handler is looking like this:

@app.route('/login/authorized')
@linkedin.authorized_handler
def authorized(resp):
    # LinkedIn returns request parameters: code & state
    if resp is None:
        return 'Access denied: reason=%s error=%s' % (
            request.args['error_reason'],
            request.args['error_description']
        )
    session['linkedin_token'] = (resp['access_token'], '')
    me = linkedin.get('people/~')  # Fetch the LInkedIn User profile for the currently authenticated user.
    email = me.data['email']
    # TODO: integrate with local app authentication system, via flask-security user_login()
    return jsonify(me.data)

There's likely some tweaks I need to do in order to properly call the linkedin.get() method above.

As it is now, the LinkedIn resp is returning:
data.error = "invalid_request"
data.error_description = u'missing required parameters, includes an invalid parameter value, parameter more then once. : Unable to retrieve access token : appId or redirect uri does not match authorization code or authorization code expired'
.message = "'Invalid response from linkedin'"
.type = "invalid_reponse"

Any thoughts?

Also, I have a full linkedin.py test/demo file that I can send to make it easier to look at....and to contribute for future users of this.

@lepture

This comment has been minimized.

Copy link
Owner

commented Aug 1, 2013

@taudep I think it is because state is required:

state   Required. A long unique string value of your choice that is hard to guess. Used to prevent CSRF. Example: state=DCEEFWF45453sdffef424

lepture referenced this issue Aug 2, 2013

@lepture

This comment has been minimized.

Copy link
Owner

commented Aug 2, 2013

@taudep I've setup an example for you, but it returns nothing. I don't know much about linkedin.

@taudep

This comment has been minimized.

Copy link
Author

commented Aug 2, 2013

I'm getting an error back when I make the API call:

me = linkedin.get('people/~')

The error from LinkedIN:

<message>Unknown authorization header {Bearer FOOOOOO}</message>

Maybe I need to implement something to turn of the Bearer token? I noticed there's some documentation on implementing a pre_request method to change the headers, maybe I should try that.s

Thank

@taudep

This comment has been minimized.

Copy link
Author

commented Aug 2, 2013

I figured out the issue: LinkedIn's API doesn't accept OAuth 2 Bearer Token Authorization headers. One needs to add the access_token as part of the query parameter instead....

@lepture

This comment has been minimized.

Copy link
Owner

commented Aug 2, 2013

@taudep I am not familiar with linkedin, and I am not sure whether it has a standard OAtuh2.

The example of linkedin works well on my laptop. It returns a blank {}

@lepture

This comment has been minimized.

Copy link
Owner

commented Aug 2, 2013

@taudep The example works now.

😢 so many non-standard so called OAuth2 services.

@taudep

This comment has been minimized.

Copy link
Author

commented Aug 2, 2013

You're fast! I shouldn't have even bothered debugging this myself. ;) Thanks.

@lepture

This comment has been minimized.

Copy link
Owner

commented Aug 2, 2013

@taudep I just had a glance at linkedin docs, it is really terrible. I've tried access_token, but it fails, after google, I found oauth2_access_token in the forum of linkedin.

@lepture

This comment has been minimized.

Copy link
Owner

commented Aug 2, 2013

@taudep This issue is resolved, I am closing it now. If you have any trouble, don't hesitate to let me know.

@lepture lepture closed this Aug 2, 2013

@taudep

This comment has been minimized.

Copy link
Author

commented Aug 2, 2013

It looks good and is working for me.

Thanks again.

@shohoku11wrj

This comment has been minimized.

Copy link

commented Oct 12, 2017

I'm using LinkedIn's accessToken in the header, as Authorization: Bearer {token_value}.
What make things interesting is, the LinkedIn accessToken, is not immediately being active if it is granted by AuthCode with a POST request. Instead, LinkedIn is prefer a GET request for exchanging authCode to accessToken.

@lepture

This comment has been minimized.

Copy link
Owner

commented May 8, 2018

In case someone found this issue. Linkedin has changed it's API, it is now a standard OAuth server. I've implemented it with loginpass here: https://github.com/authlib/loginpass/blob/master/loginpass/linkedin.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.