What is the right way to retrieve a User object from external account token

55 views
Skip to first unread message

Oleg Polyakov

unread,
Mar 28, 2013, 3:00:11 PM3/28/13
to node...@googlegroups.com
Is it possible to login through external account in ACS (facebook, twitter, foursquare)?


I want something like, but not sure how to pass nested key to query or login.

Cloud.Users.login({
    external_accounts.token: 'token...'
}, function (e) {


I also was trying to go with Cloud.SocialIntegrations approach, but it doesn't return the user if it account already exist.

//Cloud.SocialIntegrations. externalAccountLogin - creates an extra entry, which is not what I want

Facebook.isInACS = function(token){

    Cloud.SocialIntegrations.externalAccountLink({

        type: 'facebook',

        token: token

    }, function (e) {

        if (e.success) {

            var user = e.users[0];

            Ti.API.info('Success:\\n' +

                'id: ' + user.id + '\\n' +

                'petId: ' + user.petId + '\\n' +

                'first name: ' + user.first_name + '\\n' +

                'last name: ' + user.last_name);

       

        else if(e.message === "User with this external account already exists"){

            Ti.API.info(e.message);

            Ti.API.info(e.error);

            alert('Error:\\n' +

                ((e.error && e.message) || JSON.stringify(e)));

        }

    });

};

Wei Kong

unread,
Mar 28, 2013, 4:32:27 PM3/28/13
to node...@googlegroups.com
--
You received this message because you are subscribed to the Google Groups "Node.ACS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-acs+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Peter Lee

unread,
Mar 28, 2013, 4:40:52 PM3/28/13
to node...@googlegroups.com
Not sure what you meant by nested key, but if you have done 
ACS.init('oauth consumer', 'oauth secret');

You don't have to pass app key.

Oleg Polyakov

unread,
Mar 28, 2013, 5:28:40 PM3/28/13
to node...@googlegroups.com
To Wei:  externalLogin creates a new entry in the database rather then query for User based on token.  It feels like a bug to me.

To Peter: I tried a query like this but it doesn't return the User.  If pass lastname it will work.. hope you understand what I mean by nested.

Ti.API.info(token);

    Cloud.Users.query({

        page: 1,

        per_page: 10,

        where: {

            "external_accounts.token": token

        }

    },function(e){

        Ti.API.info(JSON.stringify(e));

    });

Peter Lee

unread,
Mar 28, 2013, 5:31:04 PM3/28/13
to node...@googlegroups.com
Hi Oleg,

here's how I query by id and petid. Tried on my sample app, it worked ok for me.

ACS.Users.query({
    where:"{\"_id\":\"5154b44e24b683042f002c6e\",\"petid\":\"4f5e958725dc9a0485000024\"}"
  }, function(data) {
    console.log(data);
  });


- Peter L

--

Wei Kong

unread,
Mar 28, 2013, 5:31:10 PM3/28/13
to node...@googlegroups.com
Hi Oleg,

It shouldn't, it will match the user by the external account id. Unless you pass in different id each time.  Cn you please confirm?

What is the user id?

Wei

From: Oleg Polyakov <opol...@gmail.com>
Reply-To: <node...@googlegroups.com>
--

Wei Kong

unread,
Mar 28, 2013, 5:31:59 PM3/28/13
to node...@googlegroups.com
If you already know the id of an user, there is no need to pass in petid.

From: Peter Lee <ins...@gmail.com>
Reply-To: <node...@googlegroups.com>
Date: Thursday, March 28, 2013 2:31 PM
To: <node...@googlegroups.com>
Subject: Re: What is the right way to retrieve a User object from external account token

Oleg Polyakov

unread,
Mar 28, 2013, 5:34:05 PM3/28/13
to node...@googlegroups.com
I don't know user id.  My goal is to find user id.

Input: token

Output: user_id, pet_id (User object)

Oleg

Oleg Polyakov

unread,
Mar 28, 2013, 5:37:47 PM3/28/13
to node...@googlegroups.com
Of course this works.  But I don't know the user_id and pet_id.

I only have facebook token.

All I am trying to do is verify whether the user associated his/her account with Facebook.

 Cloud.Users.query({

        page: 1,

        per_page: 10,

        where: {

            "external_accounts.token": token

        }

    },function(e){

        Ti.API.info(JSON.stringify(e));

    });


Wei Kong

unread,
Mar 28, 2013, 5:39:42 PM3/28/13
to node...@googlegroups.com
Peter will provide the query but I don't think you can rely on Facebook token should be Facebook user id
Facebook token changes

From: Oleg Polyakov <opol...@gmail.com>
Reply-To: <node...@googlegroups.com>
Date: Thursday, March 28, 2013 2:37 PM
To: <node...@googlegroups.com>
Subject: Re: What is the right way to retrieve a User object from external account token

Oleg Polyakov

unread,
Mar 28, 2013, 5:40:13 PM3/28/13
to node...@googlegroups.com
Mongodb should support my query, but it doesn't seem to work

Reply all
Reply to author
Forward
0 new messages