hemanth
hemanth

Reputation: 189

Refresh the oauth LinkedIn token

I'm working on an iOS app which uses login via LinkedIn. I'm using a web view for the user to login and getting the token from LinkedIn. If I understand it correct, The token which I received is valid for short period and hence I need to make a call to LinkedIn with the existing token to get a new token with the extended period. Can you please let me know what API I should call to refresh the token to get the new token with the extended validity?

I'm currently using https://github.com/jeyben/IOSLinkedInAPI

Upvotes: 2

Views: 924

Answers (1)

jgarewal
jgarewal

Reputation: 140

According to LinkedIn there is no direct API to call to refresh a OAuth 2 token. What's supposed to happen is if:

  1. The user is logged into LinkedIn
  2. They have a current (less than 60 days old) token

pointing them to the authentication url will trigger a refresh of their token, without needing the user to log in.

In using the iOSLinkedInAPI library, this didn't seem to be the case.

What I figured out was, the authentication flow wasn't generating a login session cookie from LinkedIn in the iOS simulator or on a device, so requirement 1 was never being met.

You need to have the user login through the regular LinkedIn login page, and this gets you that session cookie, which you can cache. After you send the user to authenticate your app, you can load that cached cookie into the NSHTTPCookieStorage sharedHTTPCookieStorage each time you want to call the authentication URL to refresh the user's token.

I created a helper class with an example if you want to check that out: iOSLinkedInTokenAuthorizer

Upvotes: 1

Related Questions