Hello,
I am trying to login a user that has been authenticated by Facebook. The first time works but after that, login always fails because Backendless thinks that I am trying to register a new user. Why? I have read the docs (https://backendless.com/docs/rest/doc.html#login-with-facebook) and both my uri and JSON payload seems to be ok according to the docs. What am doing wrong?
Here is the uri:
https://api.backendless.com/[the app’s application id]/[the app’s REST api key]/users/social/facebook/sdk/login
And here is the JSON payload:
{“accessToken”:"[the access token returned from Facebook when loggin in]",“fieldsMapping”:{“first_name”:“FirstName”,“last_name”:“LastName”,“id”:“id”}}
Here is the response from Backendless:
[Device] [isNetworkError] => false
[Device] [endpointType] => “users”
[Device] [errorCode] => 3033
[Device] [errorMessage] => “Unable to register user. User already exists.”
[Device] [httpStatusCode] => 400
[Device] [networkBytesTransferred] => 86
[Device] [headers] => table: 0x1c066ba80 {
[Device] [Connection] => “keep-alive”
[Device] [Access-Control-Allow-Methods] => “POST, GET, OPTIONS, PUT, DELETE, PATCH”
[Device] [Access-Control-Allow-Origin] => “*”
[Device] [Content-Length] => “86”
[Device] [Date] => “Sat, 20 Jan 2018 12:41:46 GMT”
[Device] [Access-Control-Allow-Headers] => “Origin, application-type, Content-Type, request, user-token, auth-key”
[Device] [Content-Type] => “application/json”
[Device] [Server] => “nginx”
[Device] }
[Device] }
Hello,
What SDK do you use? Can you provide a minimal verifiable sample? It would greatly help us to identify the problem.
Hello,
I am not using an SDK, I’m using using your REST api in a language called Lua.
Since I am using REST, I assume that the actual HTTPS call and the JSON payload is more important than the code that generated it? If you got the full uri (with the real appid and key) and the full JSON payload (with the real accesstoken), you should be able to recreate it, right? If so, please let me know how I can give give that info to you privately (i.e. not publicly here). Is there any other debug output you need that would help?
FYI: I have another app where I use the exact same code for FB authentication and that has worked for years (including after the upgrade to your v4). Now, I see that it no longer works either although I still have the same version of that app installed on my phone. That would suggest to me that there might be a more generic problem with logging in with FB on your side.
I just need a sequence of actions you perform to log in, not actually the code. I think if I perform the same requests via curl it will lead to the same results. So a list like this would be sufficient:
Go to https://facebook.com/login/xxxx?q=yyy
Take <something> from response
Go to ...
....
You don't need to share your private details, I'll run those actions on my test app.
Ok, I see.
I use the Corona framework for app development. One of the many plugins for Corona is a Facebook plugin that allows a user to be authenticated via Facebook. The steps to use that plugin are documented in the docs for the plugin (https://docs.coronalabs.com/plugin/facebook-v4a/login.html). In brief, this is what happens:
- Call the function facebook.login(), which sends an authentication request to Facebook. On a mobile device, this causes the facebook app to open (or browser if no app is installed), where the user has to confirm the authentication.
- The response triggers a listener, in which the access token is available by calling facebook.getCurrentAccessToken().
- I store that access token and make a new request for the user object by calling the function facebook.request(“me”).
- The response triggers a listener, in which data about the user is available.
- I take the access token from step 2 and build up the uri and the JSON object as specified in my original post and send it to Backendless.
The Facebook part works just as it should and produces no errors. It is only when I receive the response rom Backendless that there is an error (see my original post). Again, please note that another app that uses the exact same code for Facebook authentication no longer works now even though it is still the same version.
Can you confirm that Facebook login works for other customers? Have you made any changes at your end in the last months that may have affected this?
Hi. We fixed this issue, and we’ll notify you when new Backendless version will be released.
Hello,
Do you mean that you have had a general bug in your system preventing Facebook authentication? For how long? You have to understand that there are apps in production (including mine) that actually rely on this feature…
Second, approximately how long will it take for your fix to be released? Hours, days or weeks? I would need some kind of estimate since a lot is depending on this.
We plan next release tomorrow (24.08.2018) near midday, if it passes our QA.
Hi. We’ve fixed the problem. Please, try once again with your app.
It seems to work now, thanks.
As I have continued after your fix above, I have noticed another issue related to this. If I add properties to the user object when logging in with FB, these user properties are never registered in the Backendless user table.
Here is the uri (same as before):
https://api.backendless.com/[the app’s application id]/[the app’s REST api key]/users/social/facebook/sdk/login
And here is the JSON payload:
{“accessToken”:"[the access token returned from Facebook when loggin in]",“username”:“john”}
The “username” property never gets registered and the field remains blank in the user table. I have used the same code in other apps, setting other properties and it has worked well then. Have I misunderstood anything or is this also a bug?
As I have continued after your fix above, I have noticed another issue related to this. If I add properties to the user object when logging in with FB, these user properties are never registered in the Backendless user table.
Here is the uri (same as before):
https://api.backendless.com/[the app’s application id]/[the app’s REST api key]/users/social/facebook/sdk/login
And here is the JSON payload:
{“accessToken”:"[the access token returned from Facebook when loggin in]",“username”:“john”}
The “username” property never gets registered and the field remains blank in the user table. Is it at all possible to register other user properties when logging in with FB? It is possible with “users/register” and since both “users/register” and “/users/social/facebook/sdk/login” registers a user I thought they work the same way.
Hi.
Have you seen how api calls for registration with social networks are constructed ?
Here an example: https://backendless.com/docs/rest/doc.html#users_facebook_login
Please, pay attention for ‘fieldsMapping’ parameter.
Hello,
Yes, I have read the docs but it says that the fieldsMapping is to map facebook fields with Backendless user properties (“Keys must be the names of the Facebook fields”). In this case, I want to set a custom property that does not have anything to do with facebook. In other words, for fields that do not concern facebook, fieldsMapping does not seem to be relevant according to your docs.
Please note that for this problem, it does not matter what the custom property is. It could be anything, like e.g. “highscore”.
You have no ability to set custom properties during registration. Social login use only fields from social network, which it retrieves directly from facebook, google, twitter.
You may change user fields after it will be registerred/authenticted.
Ok, I understand, but then why are you referring to “fieldsMapping”?
Probably, Oleg haven’t understood your request completely - he was referring to the fact that you can map the properties from Facebook to the BackendlessUser using fieldsMapping. Indeed, you cannot pass any custom user properties when logging int with Facebook - and that was implemented by design. We might consider adding such possibility, but first we should know the use-cases where it would be useful. For now we cannot imagine a UI suggesting both login with Facebook and a form for custom login at the same time. Probably you could describe your case in details, especially the UI part?
In my app, users can share data between them. To be able to identify a specific user, each user has a username that is unique in the user table. So for example: if I want to share data with you, I simply enter your username in a text field.
Using the real name of another user (as fetched from FB) does not work since that is not a unique identifier. Mailaddress would have been unique but according to the FB docs, there is no guarantee that you get a mail address when asking FB for it sine the user may use his phone number to log into FB. Also, I think mail addresses are a bit more clumsy than usernames.
That leaves me with the only solution of having to register a username for a user when he logs in with FB.
How does it look on the UI, though? Do you have an additional screen where the user should put his username after logging with facebook, or does he submit it sometime earlier? Probably a few screenshots from the app would be explain much more without too many wording.