FatFractal customer forums

NoServer => NoServer Questions and Answers => Topic started by: armin65 on December 07, 2014, 04:02:10 PM

Title: Facebook login and Fatfractal integration
Post by: armin65 on December 07, 2014, 04:02:10 PM
Hello developers and users,

I am trying to use Facebook SDKs to login(already implemented) to my app and at the same time authenticate the user in fat fractal (in background) is this possible? How should I go about this? I

Any helps or pointers would be appreciated 

cheers,
armin
Title: Re: Facebook login and Fatfractal integration
Post by: dave on December 09, 2014, 12:54:58 PM
Hi armin,

Please take a look at this page giving some basic usage of ScriptAuth, which allows Facebook login (among other things):

http://fatfractal.com/v2/document/scriptable-authentication

That should get you going. If you hit any roadblocks, please let us know and we'll help you out.

Dave
Title: Re: Facebook login and Fatfractal integration
Post by: armin65 on December 10, 2014, 03:56:54 PM
Hello Dave,

thanks for helping out. I followed your suggestions and I hit a problem on deploying locally. So first question is; "Is testing Facebook-auth even possible locally?" if yes then read on ;

I am getting the following run time error from the engine when I fire up the Facebook-auth.

"
!!!APPLICATION[*********] IS READY FOR REQUESTS!!!
ERROR - STACK_TRACE - 2014.12.10 50 at 09:54:03.686 PM CET - com.fatfractal.core.nio.protocol.http.parser.HTTPException: invalid method
   at com.fatfractal.core.nio.protocol.http.parser.lolevel.ParserSettings.call_on_error(ParserSettings.java:41)
   at com.fatfractal.core.nio.protocol.http.parser.lolevel.HTTPParser.error(HTTPParser.java:1155)
   at com.fatfractal.core.nio.protocol.http.parser.lolevel.HTTPParser.execute(HTTPParser.java:312)
   at com.fatfractal.core.nio.protocol.http.HttpProtocolDecoder.decode(HttpProtocolDecoder.java:141)
   at com.fatfractal.core.nio.synchronous.ReactorHandler.run(ReactorHandler.java:104)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
   at java.lang.Thread.run(Thread.java:745)

ERROR - com.fatfractal.core.nio.protocol.http.HttpProtocolDecoder - 2014.12.10 50 at 09:54:03.706 PM CET - position[180]"

this happens with the following call:

"fatFractal.authUriForScriptAuthService(scriptAuthService, error: &authError)" (I changed the syntax to swift)

and then the client side is stuck until it throws a timed out request.

any pointers would be appreciated

cheers,
armin

Title: Re: Facebook login and Fatfractal integration
Post by: dave on December 10, 2014, 05:13:52 PM
Hi Armin,

Yes you can definitely test locally for Facebook auth, the only tricky part is setting an OAuth callback URL that Facebook will accept. I think I set the canvas app URL to something on localhost to facilitate that.

The problem you're having is related to HTTPS. I'm guessing you don't explicitly set the SSL URL of your app. If you're using our cloud footprint then this isn't an issue because it is simple to derive from the base (non-HTTPS) URL, but locally we use non-standard ports. Anyway, you need to do something like this:

Code: [Select]
FatFractal *ff = [[FatFractal alloc] initWithBaseUrl:@"http://localhost:8080/your_app_context" sslUrl:@"https://localhost:8443/your_app_context"];

Dave
Title: Re: Facebook login and Fatfractal integration
Post by: armin65 on December 11, 2014, 12:44:08 PM
Hello Dave,

It seems I still have problems getting this to work with the server. Somehow the server does not see the changes that I have made to the Auth.js file (to account for the facebookID and secret) It only sees the default one, that is when I write out the authUrl from the client side I get this:(Facebook_app_id instead of the actual id)

https://www.facebook.com/dialog/oauth?client_id=facebook_app_id&redirect_uri=.......

Any ideas what might be going wrong this time?
Title: Re: Facebook login and Fatfractal integration
Post by: dave on December 11, 2014, 01:35:52 PM
Did you redeploy your app after making the changes?
Title: Re: Facebook login and Fatfractal integration
Post by: armin65 on December 11, 2014, 02:47:41 PM
Hi dave yes I did
Title: Re: Facebook login and Fatfractal integration
Post by: dave on December 11, 2014, 04:30:34 PM
Hmm, then I don't know what else to suggest, that doesn't make sense. All I can suggest it to try deploying again, and watch the engine output for any errors that might be preventing the redeploy from succeeding. If you're using a cloud backend, you can also give me your app domain and context and I can take a look at it.
Title: Re: Facebook login and Fatfractal integration
Post by: armin65 on December 14, 2014, 06:40:22 PM
Hi Dave,
So I have solved the problem with scaffolding the app again and reinstalling the local engine, now the problem is supposedly  I have to define a callbackUri on the client side, But Facebook throws the following error for the local one I have chosen :

"Given URL is not allowed by the Application configuration.: One or more of the given URLs is not allowed by the App's settings. It must match the Website URL or Canvas URL, or the domain must be a subdomain of one of the App's domains."

callbackuri = "https://localhost:8080/darkLady/authorize"
Title: Re: Facebook login and Fatfractal integration
Post by: dave on December 16, 2014, 02:25:19 PM
Yeah Facebook it picky that way. I'd recommend going through and seeing what you app tries to use as its callback URI (on local machines it can vary a little, but should be something like http://localhost:8080/darkLady/ff/auth or http://My-Computer.local:8080/darkLady/ff/auth), then using the first part as either your app's Canvas URL or Site URL, e.g.

http://localhost:8080/darkLady

You may then need to add the domain to your app's list of App Domains (toward the top of you Facebook app settings.) Once you've done all that, things should start working. If not, post the full callback URI your app tries to use and we can go from there.

Dave
Title: Re: Facebook login and Fatfractal integration
Post by: armin65 on December 17, 2014, 05:33:40 AM
thanks for sticking with me on this,

so I tried what you suggested and I still get the same error. The complete URL that is being sent to Facebook is :

https://localhost:8443/darkLady/ff/auth?action=getAuthUri&scriptAuthService=FACEBOOK&callbackUri=darkladyfb

so I used https://localhost:8443/darkLady

then also for test purposes I also tried

https://localhost:8080/darkLady

And the thing is for an iOS app you cannot even set the canvas URL directly in the platform, you can only set the bundle Id, so I added a web platform to Facebook and then added the urls there, I guess that's what you meant with adding the urls.
Title: Re: Facebook login and Fatfractal integration
Post by: dave on December 17, 2014, 06:04:38 PM
Yep, that's right, you need to add platforms so that you can put in the URL you need to use. It's a pain but that's how it is with Facebook.

So, back to your problem. It looks like you're doing the right thing, so I'm starting to get a bit stumped. Did you add 'localhost' to the App Domains? Also if you could send/attach a screenshot of the following, it would be very helpful:

1. The exact error message you get from Facebook
2. Your Facebook app settings

Finally, just for fun, you might try using the address

http://localhost:8080/darkLady

Note that this is a plain http address (no s.) That is the protocol expected on port 8080.
Title: Re: Facebook login and Fatfractal integration
Post by: armin65 on December 18, 2014, 06:52:02 AM
Hi dave

yes I have added the localhost to app domains. Also i tried out every possible combination of http://localhost:8080/darkLady with s and without with 8080 and with 8443. And I still get the same error.

here are the screenshots

EDIT: btw I just tested the application with fat fractal servers and I get the same error, so I don't think the problem is only with local hosts, I also get the same error with or without URL Scheme suffix (here darkladyfb). I also tried filling Valid OAuth redirect URIs in dashboard and surprise surprise ; same error.
Title: Re: Facebook login and Fatfractal integration
Post by: dave on December 18, 2014, 12:42:06 PM
OK, one more question: Can you post the authorization URI you get? This is the result of a call to authUriForScriptAuthService:error:, i.e. uri below:

Code: [Select]
FatFractal *ff;
// ...
NSError *err;
NSString *uri = [ff authUriForScriptAuthService:FF_SCRIPT_AUTH_SERVICE_FACEBOOK error:&err];

Thanks ... we'll get you up and running!

Dave
Title: Re: Facebook login and Fatfractal integration
Post by: armin65 on December 19, 2014, 05:05:00 AM
Ok here it is:

https://www.facebook.com/dialog/oauth?client_id=838343536218037&redirect_uri=http%3A%2F%2Feduroam1.uni-siegen.de%3A8080%2FdarkLady%2Fff%2Fauth%3Faction%3Dredirect%26redirectUri%3Ddarkladyfb
Title: Re: Facebook login and Fatfractal integration
Post by: dave on December 19, 2014, 11:45:49 AM
OK, progress. Here's the redirect URI being given to Facebook, after URL-decoding:

http://eduroam1.uni-siegen.de:8080/darkLady/ff/auth?action=redirect&redirectUri=darkladyfb

This is the URL that Facebook tries to reconcile with your app settings, so that's why it's failing. Try putting

http://eduroam1.uni-siegen.de:8080/darkLady

in your Facebook app settings, in place of the localhost addresses we tried before. By default, ScriptAuth redirects go to your FF backend, which then re-redirects to the final URI you requested (in this case 'darkladyfb'). This is to allow for scenarios just like this one where the OAuth provider doesn't accept arbitrary callback URIs.

Dave
Title: Re: Facebook login and Fatfractal integration
Post by: armin65 on December 20, 2014, 04:54:28 PM
Ok I have tried your suggestions, but Facebook does not even accept the address as a valid one. And the Auth uri changes depending on the network I connect from. The one that I provided was from university, from my home network it changes (Armin-MacBook-Pro-2 instead of eduroam1.uni-siegen.de)

Btw. I don't know if you read one of my posts earlier but I checked the application with FF cloud URL (https://tetrolog.fatfractal.com/darkLady) and I get the same error so I think the error might be somewhere else.
Title: Re: Facebook login and Fatfractal integration
Post by: dave on December 24, 2014, 12:42:40 PM
The error is coming from Facebook, so you need to mess with your Facebook app settings until it accepts that callback URI, I don't know what else to tell you. If Facebook doesn't like .de TLD then I guess you'll need to use a cloud backend. The alternative is to not redirect the callback through the FF backend, there are settings in Auth.js to accomplish that. If you want to do this let me know and I can help you make the changes needed to Auth.js.