I'm trying to build an Ionic/Phonegap app, and I would like to authenticate against LinkedIn using OAuth. On the web, I go to http://localhost:8080/api/login
and it takes me through the OAuth dance, but on the mobile I get the following error:
{
errorCode: 0,
message: "Unable to verify access token",
requestId: "AVY9SG1I4I",
status: 401,
timestamp: 1422647386788
}
Here are some observations I made from testing various scenarios:
/api/login
seem ok on the web (Chrome)I am wondering if this has something to do with starting up an InAppBrowser every time which LinkedIn does not like?
On the client side:
.controller('SignInCtrl', function($scope, $state) {
$scope.signIn = function(user) {
console.log('Sign-In', user);
window.open(
'http://localhost:8080/api/login', '_blank', 'location=yes');
};
})
On the server side, its a Google App Engine app using webapp2:
def get(self):
auth_code = self.request.params["code"]
#tokens = step2_exchange(auth_code)
http = httplib2.Http()
resp, tokens = http.request(
"https://www.linkedin.com/uas/oauth2/accessToken?grant_type=authorization_code&client_id=CLIENT_ID&client_secret=CLIENT_SECRET&code="+ auth_code +"&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Flinkedinoauthcallback",
method='POST')
tokens = json.loads(tokens)
pdb.set_trace()
print tokens
http = httplib2.Http()
headers = { 'Authorization': 'Bearer' + tokens['access_token']}
resp, content = http.request("https://api.linkedin.com/v1/people/~/connections?modified=new&format=json", method='GET', headers=headers)
print content
self.response.headers['Content-Type'] = 'application/json'
self.response.write(json.dumps(content))