Richard Edwards
Posts: 0
Joined: Sat May 16, 2015 7:00 pm

Returning users logging in via Facebook API - how to get a sessionToken?

Hi

Hope you can help. I've followed your instructions on on how to build an app with the Facebook api, which I am using to log users in to my app.

On my app, if a user logs in via Facebook for the first time, I then automatically use the new user's details to create a user in the User collection (using their email address returned via Facebook as their username, and generating a random password), and I receive back in the response a user _id and a sessionToken. I store these locally and can use them to do things in my app, such as allow users to update their user profile.

So far all is good.

However, if a user logs in later via Facebook I don't know how to get a new sessionToken for them. This means I also can't query the Users collection to get their user _id. Unfortunately, this means users can't do many of the things in my app like update their user profile.

How can I get a sessionToken for returning users who are logging in via Facebook?

Many thanks in advance,
Richard

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Returning users logging in via Facebook API - how to get a sessionToken?

Hello Richard,

Please create "sign in" service: https://devcenter.appery.io/documenta...
It returns user's _id and sessionToken

Richard Edwards
Posts: 0
Joined: Sat May 16, 2015 7:00 pm

Returning users logging in via Facebook API - how to get a sessionToken?

Hi Sergiy

Thanks for replying. Unfortunately that doesn't work in this instance because the user is returning via Facebook, so they never use this "sign in" service and never get a sessionToken. This means they can't edit their own object in the Users collection.

To fix this, I'm trying to create a server-side sign-in script which takes their Facebook name and email address, creates a random password, adds them to the Users collection, then uses this information again to sign them in. This finally generates a sessionToken which will be passed back to the user.

That's the plan, anyway... :)

R

Richard Edwards
Posts: 0
Joined: Sat May 16, 2015 7:00 pm

Returning users logging in via Facebook API - how to get a sessionToken?

Hi again,

Hmm.. Not v successful. Can you help?

Assuming I have the user's username and password, how does a server-side login code work?

I have the following:

code
var XHRResponse = XHR.send("GET", "https://api.appery.io/rest/1/db/login" {
"headers": {
"X-Appery-Database-Id": dbId,
"Content-Type": "application/json"
},
"body": {
"username": username,
"password": test
}

Code: Select all

   }); 

/code

But I keep getting the error "SyntaxError: Unexpected token { ( @ 25 : 77 ) - var XHRResponse = XHR.send("GET", "https://api.appery.io/rest/1/db/login" {"

Also, assuming I can get it to work, how can I create a sessionToken from this and return it to the user?

Many thanks,
Richard

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Returning users logging in via Facebook API - how to get a sessionToken?

Sorry, it was incorrect link. This is what you need: https://devcenter.appery.io/documenta...

Please use facebook plugin which returns facebook access_token from Facebook_Me service

Howard Chang
Posts: 0
Joined: Mon Nov 16, 2015 6:05 am

Returning users logging in via Facebook API - how to get a sessionToken?

Hi Sergiy/Richard,

I am trying the same thing and found this post. The link is no longer working. I am also writing some server code to get the login token for User Collection after facebook login.

Code: Select all

  var XHRResponse = XHR.send("GET", "[url=https://api.appery.io/rest/1/db/login]https://api.appery.io/rest/1/db/login[/url]", { 
         "headers": { 
             "X-Appery-Database-Id": dbId, 
             "Content-Type": "application/json" 
         }, 
         "parameters": { 
         "username": username, 
         "password": password 
         } 
        }); 

How do I get the response with the token and _id return? Thanks in advance for your quick response.

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Returning users logging in via Facebook API - how to get a sessionToken?

Hello Howard,

You can get user's information from the Facebook_Me service or use access_token for any other requests to facebook

Return to “Issues”