Bod has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to connect to LinkedIn using LWP::Authen::OAuth2. Authorisation goes fine but when I come to exchange the authorisation token for an access token, I get this error:
That doesn't seem to make alot of sense to me as I would expect the OAuth2 Access Token to be empty in a request to get it!Endpoint: https://api.linkedin.com/v2/accessToken JSON: { "serviceErrorCode":65604, "message":"Empty oauth2 access token", "status":401 }
This is the bare bones of what I am doing...
The code above behaves as expected by going off to LinkedIn, authorising the app and calling the callback URL.my $linkedin = LWP::Authen::OAuth2->new( client_id => 'xxxxxxx', client_secret => 'xxxxxxx', authorization_endpoint => 'https://api.linkedin.com/uas/oauth2/a +uthorization', token_endpoint => 'https://api.linkedin.com/v2/accessTok +en', redirect_uri => "https://$ENV{'HTTP_HOST'}/cgi-bin/pos +tdog.pl?command=authorize_linkedin", scope => 'w_member_social', save_tokens => \&save_linkedin_token, ); ######################### # LinkedIn button clicked sub linkedin { my $auth_url = $linkedin->authorization_url; print "Location: $auth_url\n\n"; exit 0; }
The error (above) is generated at the request_tokens call. $data{'code'} contains the code passed as a query parameter to the callback URL.sub authorize_linkedin { my $token = $linkedin->request_tokens( code => $data{'code'}, ); print "Content-type: text-plain\n\n"; print "ERROR: $data{'error'}\n\nMessage: $data{'error_description' +}\n\n"; print "TOKEN: $token\n"; print $data{'code'}; exit 0; }
I feel I must be missing something obvious here...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Obtaining OAuth2 Access Token
by Bod (Parson) on Apr 17, 2021 at 11:42 UTC | |
|
Re: Obtaining OAuth2 Access Token
by Bod (Parson) on Apr 18, 2021 at 20:53 UTC |