Software Archive
Read-only legacy content
17060 Discussions

oauth2 issues Hybrid App

Kenny_L_
Novice
841 Views

Hi,

I am trying to authenticate my users with oauth2 for googleplus.

Everything is ok except the part to return to the app.

In the xdk Emulator I get a blank page with a label 'requesting tokens...'
The headers are good and contains the token but it stays there when I expect it to get back to the app.

I tried to debug as well but on my phone instead of getting that 'requesting tokens' screen I get an error:
'The Server refused the connection. (http://localhost:58889/http-services/api-explorer/iodocs/oauth2Callback)

I followed this tutorial:https://software.intel.com/en-us/xdk/article/oauth2-with-intelxdk-cordova-html5 and also tried https://github.com/krisrak/jquery-cordova-oauth2

so when I do that I never see the Hi or the error even ho I got the token back but still not back to the app:

function oauth2_google(){
        $.oauth2({
        auth_url: 'https://accounts.google.com/o/oauth2/auth',
        response_type: 'token',
        logout_url: 'https://accounts.google.com/logout',
        client_id: 'blablabla',
        redirect_uri: 'http://localhost:58889/http-services/api-explorer/iodocs/oauth2Callback',
        other_params: {scope:'https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile'}
    }, function(token, response){
        alert('Hi'); //makeAPICalls(token);
    }, function(error, response){
        alert(error);
    }); 
}

0 Kudos
1 Solution
Kenny_L_
Novice
841 Views

I figured it out,

The issue was that I do need the plugin InAppBrowser on the project.
It was part of the note on the issues on the https://github.com/krisrak/jquery-cordova-oauth2

This was painful to figure out since it is about a project setup instead of a code error.

So the solution is to go to the plugins management of the xdk project and add InAppBrowser and that fix the issue, I hope this will help others

View solution in original post

0 Kudos
4 Replies
PaulF_IntelCorp
Employee
841 Views

I've asked one of my colleagues, who is more knowledgable about this feature, to help you out.

0 Kudos
Kenny_L_
Novice
842 Views

I figured it out,

The issue was that I do need the plugin InAppBrowser on the project.
It was part of the note on the issues on the https://github.com/krisrak/jquery-cordova-oauth2

This was painful to figure out since it is about a project setup instead of a code error.

So the solution is to go to the plugins management of the xdk project and add InAppBrowser and that fix the issue, I hope this will help others

0 Kudos
Anusha_M_Intel1
Employee
841 Views

@Kenny,

I noticed the tutorial references Cordova InAppBrowser several times. "Open Oauth2 authorization page in Cordova InAppBrowser". 

But I will request the author to make it more explicit about adding the InAppBrowser plugin to the project. Glad you were able to fix it. 

0 Kudos
Kenny_L_
Novice
841 Views

Thank you for following up!

0 Kudos
Reply