Reputation: 681
I am trying to login using LinkedIn. I manage to get the accesstoken but for a split second before redirecting to the page I tell it to, i see this error
HTTP Error 404.0 - Not Found The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
and this is the link
http://localhost:80/callback?code=****&state=WQ7IIHGw
while Ionic works on my localhost:8100, I have set the the Authorized rediect URLS to http://localhost/callback in the linked in developer page
Also, when I set the linked in redirect URL to anything but the localhost/call back i get this error
Invalid redirect_uri. This value must match a URL registered with the API Key.
Upvotes: 1
Views: 735
Reputation: 24962
Follow/verify this steps:
Setup LinkedIn account developer options: https://www.linkedin.com/developer/apps/
After adding application go to its settings:
Client ID
and Client Secret
$cordovaOauth
Setup Ionic app:
Install cordovaOauth bower install ng-cordova-oauth -S
Add <script src="lib/ng-cordova-oauth/dist/ng-cordova-oauth.js"></script>
to index.html
and 'ngCordovaOauth'
to apps.js
Add $cordovaOauth
to controller dependency
Add function to controller (only Client ID
and Client Secret
need to be replaced by the data from LinkedIn dev account):
$scope.linkedInLoginIonic = function () {
var linkedinUriApi = "https://api.linkedin.com/v1/people/~:(email-address,first-name)?format=json&oauth2_access_token=";
$cordovaOauth.linkedin("Client ID", "Client Secret", ['r_basicprofile', 'r_emailaddress'])
.then(function (success) {
// Here you will get the access_token
console.log('Granted access to linkedin');
console.log(JSON.stringify(success));
// In request below my default header is disabled - otherwise Linkedin API will reject request
$http(
{method: 'GET',
url: linkedinUriApi + success.access_token,
headers: {Authorization: undefined}
}).then(function (response) {
console.log(response);
}, function (error) {
console.log(error);
console.log('Ionic LinkedIn API request after successful login failed');
});
},
function (error) {
console.log(error);
});
};
Tips:
Cannot authenticate via a web browser
address
and first-name
in https://api.linkedin.com/v1/people/~:(email-address,first-name)?
$cordovaOauth
part ['r_basicprofile', 'r_emailaddress']
Upvotes: 3