I've been working with torii add-on to authenticate via linkedin.
I'm able to get the authorization code correctly, but having trouble to get the access token following this official tutorial:
If I follow this option, I get the following error:
XMLHttpRequest cannot load https://linkedin.com/uas/oauth2/accessToken?grant_type=authorization_code&c…&redirect_uri=REDIRECT_URI&client_id=CLIENT_ID&client_secret=CLIENT_SECRET. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'my-host.com:4200' is therefore not allowed access.
linkedInAccessToken: function(authenticationCode){
return new Ember.RSVP.Promise(function (resolve, reject) {
Ember.$.ajax({
type: "GET",
url: "https://linkedin.com/uas/oauth2/accessToken?grant_type=authorization_code&code="+ authenticationCode +"&redirect_uri=REDIRECT_URI&client_id=CLIENT_ID&client_secret=CLIENT_SECRET",
success: function (response) {
console.log("ACCESS_TOKEN" + data.access_token);
resolve(data);
},
error: function (request, textStatus, error) {
console.log(error);
reject(error);
}
});
});
},
If I follow this other option, I get this error:
Refused to execute script from 'https://linkedin.com/uas/oauth2/accessToken?grant_type=authorization_code&c…llback&callback=jQuery1113038602466485463083_1445461451847&_=1445461451848' because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled.
linkedInAccessToken: function(authenticationCode){
return new Ember.RSVP.Promise(function (resolve, reject) {
Ember.$.ajax({
type: "GET",
url: "https://linkedin.com/uas/oauth2/accessToken?grant_type=authorization_code&code="+ authenticationCode +"&redirect_uri=REDIRECT_URI&client_id=CLIENT_ID&client_secret=CLIENT_SECRET&callback=jsonpcallback",
dataType: 'jsonp',
success: function (response) {
console.log("ACCESS_TOKEN" + data.access_token);
resolve(data);
},
error: function (request, textStatus, error) {
console.log(error);
reject(error);
}
});
});
},
jsonpcallback: function(data){
},
This last option returns the json on the network tab, but because of this problem i'm not being able to process it.
LinkedIn OAuth2 only returns json that's why i'm having the problem using 'jsonp'. On the other hand it's not cors either, that's why I'm having the problem on the first example.
Do you have any idea to help me solve this?
Thanks :)
I had this problem the other day. If you are authorizing through torii and the oauth linkedin API, you'll need to pass the authorization code to your back end and let it deal with the swapping.
Unless you're using the JavascriptSDK API with linkedin they don't allow cross-origin-requests.