Linkeddin Exchange Authorization Code for an Access Token using AngularJS

161 views
Skip to first unread message

Polokh Andrey

unread,
Aug 3, 2016, 8:50:30 AM8/3/16
to AngularJS

I am using AngularJS 1.5.8 and trying to implement Linkedin API.

Linkedin authorization has two steps:

1. Request an Authorization Code


I successfully passed this step and received authorization code

2. Exchange Authorization Code for an Access Token


I am trying to send POST request and it fails. Not sure what I am doing wrong. The code looks like this:

var url = 'https://www.linkedin.com/oauth/v2/accessToken';
var params = 
    {
       'grant_type':'authorization_code',
       'code': CODE,
       'redirect_uri': REDIRECT_URL,
       'client_id': CLIENT_ID,
       'client_secret': CLIENT_SECRET
    };

$http({
 method: 'POST',
 headers: {
        'Content-Type': 'application/x-www-form-urlencoded' 
 },
 url: url,
 data: params
})
.success(function (result) {
     console.log(result);
}).error(function (data, status, header, config) {
     console.log(data, status, header, config);
});

Every time I've got next error:

 XMLHttpRequest cannot load https://www.linkedin.com/oauth/v2/accessToken. 
No 'Access-Control-Allow-Origin' header is present on the requested resource.
 Origin 'http://localhost:8080' is therefore not allowed access. 
The response had HTTP status code 400.

Please, help to fix this. 
Many thanks

Michael Dundas

unread,
May 4, 2018, 11:33:28 PM5/4/18
to Angular and AngularJS discussion
Did this get resolved?  I can't seem to find an answer anywhere and I have the exact same scenario and error message.

-mike.

Surendra.M

unread,
Oct 1, 2018, 6:05:39 AM10/1/18
to Angular and AngularJS discussion
Hi Polokh Andrey,
Hope you solved the issue.

Currently I am also working on  implementation of OAUTH in my AngularJS application.

When the request for the authorization code raises , it will ask for credentials, so, in my case the credentials page should be open in new pop up window.
After entering the credentials, the authorization code should be passed to the child page.

So, can you give me some inputs how to handle this????

Thanks in Advance.
Surendra M.
Reply all
Reply to author
Forward
0 new messages