Issues with social login

225 views
Skip to first unread message

nexiz

unread,
Jun 4, 2015, 4:18:16 PM6/4/15
to baa...@googlegroups.com
Hi,

I am having a few issues with the social login API for google+, when developing for android.

a) According to info posted under "https://github.com/baasbox/baasbox/issues/498" it would be needed to have an application key tied to the android app and a web api token key/secret to fill out in the baasbox server interface. However using the web api key it is not possible to get the social login to work. It always gives an error "Unable to validate provided token". If I however change the web api token key in the baasbox server by the android app key, it does work. Is this the expected behavior?

b) I also found an issue with the baasUser.linkToProvider method in Android.  According to the description in your API the function should return error code "500" if another user with the same token already exists. However, the method call links to a new user even if another token already exists on the server. Therefore, two or more users end up being linked to the same google+ account,which should not happen.

c) Lastly, I was looking for a method to check if a google+ account was already linked to a user in the database (a user to g+ exists, but not the other way around). The only method that comes close is the BaasUser.signUpWithProvider, it however creates a new user if it does not find a linked user in the database, which is not the behavior I want. I'd like the method to return an error code so that I can decide myself if I create a new user or instead the option is offered to link with an existing account.

Regards.

CoffeeBean

unread,
Jul 1, 2015, 6:20:24 AM7/1/15
to baa...@googlegroups.com
Hi Can you please look into diz???

im mugging up with this code for few days
Here i'm authenticating with google and able to get token from google and passing to a method logincb() where it will create the user for the provided token.
When i call the http request with necessary parameters its showing error some kind off (Unable to print the whole message as im getting this as an alert statement in mobile android app)
{ "result": "error", "message": "java.lang.
NullPointerException com.baasbox.service.sociallogin.GooglePlusLoginService.extractUserInfo
Unknown Source} and origin = file://

$scope.googlelogin = function(isLink){
        window
.alert("entered googlelogin");
       
var clientId = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
       
var clientSecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
       
var ref = window.open('https://accounts.google.com/o/oauth2/auth?client_id=' + clientId + '&redirect_uri=http://localhost/callback&scope=https://www.googleapis.com/auth/urlshortener&approval_prompt=force&response_type=code&access_type=offline', '_blank', 'location=no');
        window
.alert("got the ref");
       
ref.addEventListener('loadstart', function(event) {
            window
.alert("entered add ref eveent listener"+event.url);
                window
.alert("entered eventURL");
                requestToken
= (event.url).split("code=")[1];
                window
.alert("got Request token"+requestToken);
                $http
({method: "post", url: "https://accounts.google.com/o/oauth2/token", data: "client_id=" + clientId + "&client_secret=" + clientSecret + "&redirect_uri=http://localhost/callback" + "&grant_type=authorization_code" + "&code=" + requestToken })
                   
.success(function(data) {
                        accessToken
= data.access_token;
                        window
.alert("access token is==:"+accessToken);
                       
//$location.path("/secure");
                        $scope
.logincb(accessToken, 'google', isLink);
                       
                   
})
                   
.error(function(data, status) {
                        alert
("ERROR: DAMMMMNNNN"+JSON.stringify(data));
                   
});
               
ref.close();
       
});

and my logincb() is

$scope.logincb = function(t,social,isLink){
            alert
("entered logincb()"+social);
           
var token = t;
           
var link = isLink ?  'linkWith':'loginWith';
           
var headers = {'Content-Type': 'application/json','X-BAASBOX-APPCODE':1234567890}
           
/*if(isLink){
                headers['X-BB-SESSION'] = auth.getToken();
            }*/

            alert
("entered $apply method");
           
                $http
({
                    method
: isLink?'PUT':'POST',
                    url
: serverUrl+"/social/"+social+"?oauth_token="+token+"&oauth_secret="+token,
                    data
:{},
                    headers
: headers
               
}).success(function(data){
                   
if(!isLink){
                        alert
("success"+data["data"].user);
                         
//$location.path("/posts")
                     
}else{
                          alert
("loaf from exixting");
                         
//auth.getLogins().push(social);
                     
}
                             
               
}).error(function(data){
                    alert
("error block"+JSON.stringify(data));// Here i'm getting the error block which i have specified above
                    console
.log(data);
               
})
           
       
}

Can anybody help me what i'm doing wrong.

My console.developers.google.com configuration is

Client ID: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Email address: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Client secret
XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Redirect URIs : http://localhost/callback
JavaScript origins
: none

CoffeeBean

unread,
Jul 9, 2015, 3:24:00 AM7/9/15
to baa...@googlegroups.com
Hi,

I'm getting below error for the above code


 "result": "error",
   
"message": "java.lang.NullPointerException\n\tat com.baasbox.controllers.Social.extractOAuthTokensFromRequest(Social.java:122)\n\tat com.baasbox.controllers.Social.lambda$loginWith$217(Social.java:150)\n\tat com.baasbox.controllers.Social$$Lambda$65/1292737550.apply(Unknown Source)\n\tat com.baasbox.db.DbHelper.lambda$withDbFromContext$247(DbHelper.java:838)\n\tat com.baasbox.db.DbHelper$$Lambda$17/1018682605.apply(Unknown Source)\n\tat play.core.j.FPromiseHelper$$anonfun$promise$2.apply(FPromiseHelper.scala:34)\n\tat scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24)\n\tat scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24)\n\tat play.core.j.HttpExecutionContext$$anon$2.run(HttpExecutionContext.scala:37)\n\tat akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:42)\n\tat akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:386)\n\tat scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)\n\tat scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)\n\tat scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)\n\tat scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)\n",
   
"resource": "/social/google",
   
"method": "POST",
   
"request_header": {
       
"X-BAASBOX-APPCODE": [
           
"1234567890"
       
],


giastfader

unread,
Jul 9, 2015, 8:33:55 AM7/9/15
to baa...@googlegroups.com
What version?

CoffeeBean

unread,
Jul 9, 2015, 8:40:10 AM7/9/15
to baa...@googlegroups.com
0.9.4 version.

If i send via rest client I'm getting the above error.

If i user the below code in my mobile its entering into error block of http request and printing " "(data variable is not having anything).

$scope.createUserWithBaasbox = function(t,social,isLink){
       
       
var token = t;
       
var headers = {'X-BAASBOX-APPCODE':1234567890}
       
if(isLink){
            alert
("entered if");
            headers
['X-BB-SESSION'] = auth.getToken();

       
}
        alert
("entered $apply method");
        $http
({
            method
: isLink?'PUT':'POST',

            headers
: headers,

            url
: serverUrl+"/social/"+social+"?oauth_token="+token+"&oauth_secret="+token,
            data
:{}

       
}).success(function(data){
       
if(!isLink){
           alert
("success"+JSON.stringify(data));
           
var userSessionValue = data['data']['X-BB-SESSION'];
           
//alert(userSessionValue);
           
var visibleByRegisteredUsers = data['data'].visibleByRegisteredUsers;
           
if(visibleByRegisteredUsers.email == undefined){
                alert
(JSON.stringify(visibleByRegisteredUsers));
                visibleByRegisteredUsers
.email = data['data'].visibleByTheUser.email;
               
//alert(visibleByRegisteredUsers.email);
                visibleByRegisteredUsers
.type = "SUBSCRIBER";
                visibleByRegisteredUsers
.redeemedCount = 0;
                visibleByRegisteredUsers
.name = data['data'].visibleByTheUser.name;
                visibleByRegisteredUsers
.dateOfBirth = "";
                visibleByRegisteredUsers
.emailSubscription = true;
               
//alert("heyyy"+JSON.stringify(visibleByRegisteredUsers));
                visibleByRegisteredUsers
.shareCount = 0;
               
if(social == 'facebook'){
                    visibleByRegisteredUsers
.gender = data['data'].visibleByTheUser.gender;
               
}
               
else{
                    visibleByRegisteredUsers
.gender = "";
               
}
               
//alert(JSON.stringify(visibleByRegisteredUsers));
                $http
({
                    method
:'PUT',
                    url
: serverUrl+"/me",
                    data
:{"visibleByRegisteredUsers" : visibleByRegisteredUsers},
                    headers
: {'Content-Type': 'application/json',
                             
'X-BB-SESSION' : data['data']['X-BB-SESSION']
                   
}
               
}).success(function(data){
                    alert
(data);
                   
//TODO:local storage has to be implemented
                    $state
.go("app.dummy");
                   
//console.log(JSON.stringify(data));
               
})
               
.error(function(data){
                       alert
("error block is",data);
                       
//console.log(JSON.stringify(data));
               
})
           
}
           
//alert("not entered into if loop");
           
//TODO:local storage has to be implemented
            $state
.go('app.dummy');
           
//auth.setUser(data["data"].user,{"sso":social,"auth_token":token,"auth_secret":token},data["data"]["X-BB-SESSION"]);
           
//$location.path("/posts")
       
}
       
else{
           
//alert("loaf from exixting");
           
//auth.getLogins().push(social);
       
}
       
}).error(function(data){
           alert
("error block is"+JSON.stringify(data));
           console
.log(JSON.stringify(data));
       
})
        alert
("before $scope.$apply");
   
}

I'm stuck with the social login. I'm able to get the token but unable to complete the login.
Help me on this @giastfader
Message has been deleted

ori_rideon

unread,
Nov 8, 2015, 8:52:29 AM11/8/15
to BaasBox
Hi

I'm getting the same error when posting to /social/facebook:

curl -X POST -H "X-BAASBOX-APPCODE: 1234567890"  http://www.<HOSTNAME>.com:9000/social/facebook?oauth_token=<TOKEN>&oauth_secret=<TOKEN>

Error:

{"result":"error","message":"java.lang.NullPointerException\n\tat com.baasbox.controllers.Social.extractOAuthTokensFromRequest(Social.java:110)\n\tat com.baasbox.controllers.Social.loginWith(Social.java:138)\n\tat Routes$$anonfun$routes$1$$anonfun$applyOrElse$25$$anonfun$apply$25.apply(routes_routing.scala:897)\n\tat Routes$$anonfun$routes$1$$anonfun$applyOrElse$25$$anonfun$apply$25.apply(routes_routing.scala:897)\n\tat play.core.Router$HandlerInvoker$$anon$7$$anon$2.invocation(Router.scala:183)\n\tat play.core.Router$Routes$$anon$1.invocation(Router.scala:377)\n\tat play.core.j.JavaAction$$anon$1.call(JavaAction.scala:56)\n\tat play.GlobalSettings$1.call(GlobalSettings.java:64)\n\tat com.baasbox.controllers.actions.filters.ConnectToDBFilter.call(ConnectToDBFilter.java:81)\n\tat com.baasbox.controllers.actions.filters.AdminCredentialWrapFilter.call(AdminCredentialWrapFilter.java:68)\n\tat play.core.j.JavaAction$$anon$3.apply(JavaAction.scala:91)\n\tat play.core.j.JavaAction$$anon$3.apply(JavaAction.scala:90)\n\tat play.core.j.FPromiseHelper$$anonfun$flatMap$1.apply(FPromiseHelper.scala:82)\n\tat play.core.j.FPromiseHelper$$anonfun$flatMap$1.apply(FPromiseHelper.scala:82)\n\tat scala.concurrent.Future$$anonfun$flatMap$1.apply(Future.scala:251)\n\tat scala.concurrent.Future$$anonfun$flatMap$1.apply(Future.scala:249)\n\tat scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32)\n\tat play.core.j.HttpExecutionContext$$anon$2.run(HttpExecutionContext.scala:37)\n\tat akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:42)\n\tat akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:386)\n\tat scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)\n\tat scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)\n\tat scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)\n\tat scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)\n","resource":"/social/facebook","method":"POST","request_header":{"Accept":["*/*"],"Host":["www.<HOSTNAME>.com:9000"],"User-Agent":["curl/7.43.0"],"X-BAASBOX-APPCODE":["1234567890"]},"API_version":"0.9.4","http_code":500}


It looks a little bit like a bug that came back... :(


Ori


Yaron

unread,
Nov 8, 2015, 12:39:49 PM11/8/15
to BaasBox
Hi Ori,

You are using POST so you shouldn't put these two parameters in the URI. 

They should be inside the request body. 

You can use Postman to simulate this request. 

Let me know if you need an additional assistance.

All the best,
Yaron. 

Yaron

unread,
Nov 8, 2015, 12:44:58 PM11/8/15
to BaasBox
BTW, if you still insists to test your app with CURL command line you can try this format: 

-d "oauth_token=OAUTH_TOKEN" \
-d "oauth_secret=OAUTH_SECRET" \
-H X-BB-SESSION:2605d809-03f0-4751-8f8e-5f658e179a23

Regards,
Yaron. 

ori_rideon

unread,
Nov 9, 2015, 5:31:23 AM11/9/15
to BaasBox
Hi, 
Thanks for the help! Unfortunately it doesn't work with POST as well (NullPointerException)
BaasBox 0.9.4
-d "oauth_token=<FACEBOOK_TOKEN>" \
-d "oauth_secret=<FACEBOOK_TOKEN>" \
-H X-BB-SESSION:48d6fe06-62a3-4b39-af9a-ef2397687bf8 -H "X-BAASBOX-APPCODE: 1234567890"

Result:

{"result":"error","message":"java.lang.NullPointerException\n\tat com.baasbox.controllers.Social.extractOAuthTokensFromRequest(Social.java:110)\n\tat com.baasbox.controllers.Social.loginWith(Social.java:138)\n\tat Routes$$anonfun$routes$1$$anonfun$applyOrElse$25$$anonfun$apply$25.apply(routes_routing.scala:897)\n\tat Routes$$anonfun$routes$1$$anonfun$applyOrElse$25$$anonfun$apply$25.apply(routes_routing.scala:897)\n\tat play.core.Router$HandlerInvoker$$anon$7$$anon$2.invocation(Router.scala:183)\n\tat play.core.Router$Routes$$anon$1.invocation(Router.scala:377)\n\tat play.core.j.JavaAction$$anon$1.call(JavaAction.scala:56)\n\tat play.GlobalSettings$1.call(GlobalSettings.java:64)\n\tat com.baasbox.controllers.actions.filters.ConnectToDBFilter.call(ConnectToDBFilter.java:81)\n\tat com.baasbox.controllers.actions.filters.AdminCredentialWrapFilter.call(AdminCredentialWrapFilter.java:68)\n\tat play.core.j.JavaAction$$anon$3.apply(JavaAction.scala:91)\n\tat play.core.j.JavaAction$$anon$3.apply(JavaAction.scala:90)\n\tat play.core.j.FPromiseHelper$$anonfun$flatMap$1.apply(FPromiseHelper.scala:82)\n\tat play.core.j.FPromiseHelper$$anonfun$flatMap$1.apply(FPromiseHelper.scala:82)\n\tat scala.concurrent.Future$$anonfun$flatMap$1.apply(Future.scala:251)\n\tat scala.concurrent.Future$$anonfun$flatMap$1.apply(Future.scala:249)\n\tat scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32)\n\tat play.core.j.HttpExecutionContext$$anon$2.run(HttpExecutionContext.scala:37)\n\tat akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:42)\n\tat akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:386)\n\tat scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)\n\tat scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)\n\tat scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)\n\tat scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)\n","resource":"/social/facebook","method":"POST","request_header":{"X-BAASBOX-APPCODE":["1234567890"],"Content-Length":["444"],"Accept":["*/*"],"X-BB-SESSION":["48d6fe06-62a3-4b39-af8a-ef2397687bf8"],"Content-Type":["application/x-www-form-urlencoded"],"User-Agent":["curl/7.43.0"],"Host":["localhost:9000"]},"API_version":"0.9.4","http_code":500}

giastfader

unread,
Nov 9, 2015, 5:38:00 AM11/9/15
to BaasBox
OPS!
You have found an error into the doc.
Data must be posted as JSON object, using the content-type: application/json.
Try:

curl -X POST -H "x-baasbox-appcode: 1234567890" -H "Content-Type: application/json" -d '{
  "oauth_token":"...",
 
"oauth_secret":"..."
}'
'http://localhost:9000/social/facebook'



ori_rideon

unread,
Nov 9, 2015, 5:38:28 AM11/9/15
to BaasBox
Finally I found a solution! 

A. Use POST.
B. Use the JSON syntax in the body.
C. Add a Content-type:application/json header.

Working curl command:

 --data "{\"oauth_token\":\"<facebook token>\", \"oauth_secret\" : \"<facebook token\"}" \
 -H X-BB-SESSION:48d6fe06-62a3-5b39-af8a-ef2397687bf8 \
 -H "X-BAASBOX-APPCODE: 1234567890" \
 -H "Content-type:application/json"

ori_rideon

unread,
Nov 9, 2015, 5:50:48 AM11/9/15
to BaasBox
Thanks! Found it the same time :-)

A.G.

unread,
Feb 18, 2017, 2:14:09 PM2/18/17
to BaasBox
This "bug" is still present in the docs. I needed days to figure out why baasbox is getting a NullPointerException.
Reply all
Reply to author
Forward
0 new messages