Start a new topic

Integrating with Facebook App

I'm doing a Facebook App version (runs in the browser) of my mobile app. How can I authenticate the user without creating a popup window? Better yet, how can we piggyback on the fact that the user is already logged into facebook and just put up a popup to grant access? I'm finding that the popup window for authentication is a HUGE barrier for users.

Hey Daniel, I think that this depends on the requirements of Facebook-- I don't know if there's a decent way to get around it.
It looks like the REST API is the way to go for this. It sounds like I can do an authentication with facebook's sdk, then use the resulting id and token in a Kinvey REST call.
Social Login isn't working for me in the REST API. When I first create the user, I get back an expected result - user data. If I try to login as that user using the facebook authentication I created it with, I get back 400 (bad request error):



This code creates the user, using the FB Javascript API to login to Facebook and get the authorization key:

var response = Kinvey.Persistence.Net.request(

"POST",

"https://baas.kinvey.com/user/APP_KEY",

{

"_socialIdentity":

{

"facebook":

{

"access_token":FB.getAuthResponse().accessToken,

"expires":FB.getAuthResponse().expiresIn

}

}



},

{

"Authorization": "Basic " + Kinvey.Persistence.Net.base64('APP_KEY:APP_SECRET'),

"X-Kinvey-API-Version": 3

}

)

That part works fine and it creates a new Kinvey user (though it should really be returning an existing user that already uses those credentials).



My understanding is that following code, identical except in the URL which I am adding /login to, should login using the same facebook account I just created the user with:

var response = Kinvey.Persistence.Net.request(

"POST",

"https://baas.kinvey.com/user/APP_KEY/login",

{

"_socialIdentity":

{

"facebook":

{

"access_token":FB.getAuthResponse().accessToken,

"expires":FB.getAuthResponse().expiresIn

}

}



},

{

"Authorization": "Basic " + Kinvey.Persistence.Net.base64('APP_KEY:APP_SECRET'),

"X-Kinvey-API-Version": 3

}

)



No dice, I get a 401 error:



Request URL:https://baas.kinvey.com/user/APP_KEY/login

Request Method:POST

Status Code:401 Unauthorized

Request Headersview source

Accept:application/json, text/javascript, */*; q=0.01

Accept-Encoding:gzip,deflate,sdch

Accept-Language:en-US,en;q=0.8

Authorization:Kinvey APP_KEY:APP_SECRET base64

Cache-Control:no-cache

Connection:keep-alive

Content-Length:281

Content-Type:application/x-www-form-urlencoded; charset=UTF-8

Host:baas.kinvey.com

Origin:https://gethiyu.com

Pragma:no-cache

Referer:https://gethiyu.com/

User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36

X-Kinvey-API-Version:3

Form Dataview sourceview URL encoded

{"_socialIdentity":{"facebook":{"access_token":"MYTOKEN_FROM_FB","expires":4713}}}:

Response Headersview source

Access-Control-Allow-Credentials:true

Access-Control-Allow-Methods:POST

Access-Control-Allow-Origin:https://gethiyu.com

Access-Control-Expose-Headers:Location

Connection:keep-alive

Content-Length:167

Content-Type:application/json; charset=utf-8

Date:Thu, 14 Nov 2013 01:46:19 GMT

Server:nginx

WWW-Authenticate:Kinvey realm="Kinvey authorization needed"

X-Kinvey-API-Version:3

X-Kinvey-Request-Id:6c44468165924351b2464346edb1cc8f

X-Powered-By:Express
Hi Daniel, I've got an engineer taking a look at this. Did you get anywhere with it since your last post?
Hello

Did you ever make it work or got a response on this? I need to implement the same feature

Thanks...
No, I wasn't able to figure it out and hadn't heard back from engineering.
Hello Caroline, do you have any update on this?
I am not sure to what extend you are running into the same problem as reported by Daniel. Either way, in the requests it looks like you’re using `socialIdentity` instead of `_socialIdentity` (note the underscore), which will lead to the faulty behavior you described.
actually i am using cordova and angularjs.

I am able to call the cordova facebook plugin to retrieve the authorization token, but i cant find any documentation on how to pass the token back to kinvey using:



$kinvey.Social.connect(null, facebook');



could you help me on that?
You should be able to use:



```

$kinvey.User.login({

_socialIdentity: {

facebook: {

access_token: '',

expires_in: ''

}

}

});

```
Thanks. It works create. Now i have another question:

when the access_token from facebook has changed, how do i prevent kinvey from creating a new user?
Using a different access code shouldn’t matter when logging in - internally we retrieve a user by its Facebook ID, which will be the same.
Login or Signup to post a comment