Question

(repost from https://groups.google.com/forum/?hl=en&fromgroups=#!topic/hybridauth/CWo2R9suYts)

Starting with Facebook, I'm trying to use the provider Javascript SDKs to login and have HybridAuth "know" about it. Any help would be appreciated.

I started by including the configuration IDs in the data I pass to the View so I can use them when calling Javascript login functions. So in the middle of the GetProviders function of the Hybrid_Auth class, I added:

if(array_key_exists('keys', $params) && array_key_exists('id', $params['keys']))
$idps[$idpid]['id'] = $params['keys']['id'];

My Javascript includes something like this:

FB.init({
appId:'<?php echo $providers['Facebook']['id']; ?>',
cookie:true,
status : true,
xfbml:true
});

So far so good.

But after logging in (i.e., FB.login()) of course HybridAuth doesn't know and doesn't have the user information.

Then to "force" it, I tried calling the ".../hauth/login/Facebook" method via Ajax:

$.ajax({
type: "POST",
url: ".../hauth/login/Facebook",
cache: false,
...

Unfortunately, it seems like a number of 'redirects' in HybridAuth make this not work. I even added "data: {ajax:true}," to the Ajax call and tried to modify HyrbidAuth to not redirect if it $_POST['ajax'] existed. That didn't seem to do it either. (I even removed the "die();" at the end of the redirect() function to no avail.)

I'm thinking I'm either on the right track or I need to add a new HybridAuth method to detect and store data for all or specific connections that already exist.

Any ideas?

Thanks.

Was it helpful?

Solution

I attempted several ways to login to a Provider using a Javascript SDK and integrate that with HyrbidAuth. No solution was very pretty, and each required that I alter HybridAuth which would be difficult to maintain. I finally determined that the best solution was to follow the "widget" example included with HybridAuth.

I didn't use the widget, but the code shows a method for opening and closing a separate smaller window using Javascript. That window's URL contains information for the server to call HybridAuth's 'authenticate' method which redirects to the Provider's login/approval page.

The effect is essentially the same: the user stays on the same page while authenticating with a Provider in a separate "window."

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top