It works if and only if the user is signed into LinkedIn at the time of making the OAuth2 request.
If the user is not signed in then we encounter an error.
Sequence of our actions:
- successfully fetch the fresh access token
- using the access token, post to the api endpoint
https://api.linkedin.com/v1/people/\~
After this we receive a 401 with the following content:
{
"errorCode": 0,
"message": "Unable to verify access token",
"requestId": "C0DUCX81SA",
"status": 401,
"timestamp": 1421946470523
}
Sometimes, after some time passed, a retry with the same Access Token gives a 200. Sometimes not.
If the user logs in to LinkedIn during this "401 period" then magically the previously fetched access token starts to work.
I am at a loss how to solve this, as it seems to be an issue at LinkedIn.
Has anybody any suggestions or did anybody see this behavior before?
We tried cookie settings, wait periods before our request etc.
We are adding LinkedIn OAuth2 authentication to Zotonic [1], but are now stuck with a non-working module.
Edit:
Someone referred to two discussions at LinkedIn. His reply now regretfully disappeared from the discussion below.
These are the links:
https://developer.linkedin.com/forum/unable-verify-access-token
I have tried all suggestions in these discussions, to no avail.
Edit #2:
Checking the first discussion at LinkedIn shows that I am not the only one having these consistency issues. Something at LinkedIn is going wrong if the user has cleared cookies or has to sign in to LinkedIn during the OAuth "dance" https://developer.linkedin.com/forum/unable-verify-access-token#comment-36950
Update
Solved, thanks to Matthijs Bierman, see answers below.