0

I am using the OAuth Facebook controller add-on for ATK4.

  • It works as expected when authenticating with Facebook from a regular desktop browser.
  • It works when authenticating using a mobile browser that is telling face book that it's a desktop browser.
  • It does not work when Facebook detects a mobile browser and redirects to m.facebook.com/dialog/oath.

What's more, is that it works fine for signups from mobile browsers (ie, when Facebook asks the user to give permission to the app).

The login flow stops with an Error 500 at: https://m.facebook.com/dialog/oauth?redirect_uri={my_url_encoded_landing_page_where_the_OAuth_controller_lives}&scope=email&client_id={fb_app_id}

What the hell is going on here? There isn't some difference between the Facebook mobile service and the regular one that the addon isn't taking care of, or is there?

It must be something I'm doing wrong. In init() on the page that handles the FB, I am doing the following:

function init(){
    parent::init();
    $f = $this->add("oauth/Controller_OAuth_Facebook", array('sign_method'=>'PLAINTEXT'));

    if ($fbtoken = $f->check()) {
        $f->setSignatureInfo(); 
        $f->setAuthToken($fbtoken["access_token"], $fbtoken["expires"]); 

        $s = $this->add("sni/Controller_SNI_Facebook"); 
        $s->setOAuth($f);
        // ... 
        // grab profile from SNI, database lookup, session stuff, etc
        // ...
    }
}

I've tried all three sign_methods, and tried leaving it alone, but that doesn't make much difference because the user is not making it back to the controller with an access token to use anyway.

I tried creating a new app with Facebook and I get the same issues with a basically vanilla configuration on that. I've only marked and specified the "Website with Facebook Login" site URL integration.

The image below was captured from Chrome after overriding the user agent to a mobile device to trigger the forward to facebook's mobile servers: Screen shot of request

Facebook closed my bug report with them stating that it's not an issue since no one else is reporting the bug. I am removing the ATK4 tag, as I get the same issue using the example PHP code provided by Facebook on GIT.

3
  • which smartphone are you using?
    – jancha
    May 9, 2013 at 9:57
  • Can you check project invest-game.com? try log-in there, it's using atk4 oauth Facebook. worked fine for my iphone.
    – jancha
    May 9, 2013 at 10:03
  • Logging into that works fine on the test devices I've observed problems with. There are slight differences between the request headers are sending to fb when referred from your site vs those when referred from my site, but nothing I'd expect to cause a server side error. I must be doing something wrong.
    – Will
    May 9, 2013 at 16:14

4 Answers 4

1

Created dedicated example here: http://demo.ambienttech.lv/d.html?ns=d3

Example is downloadable and includes instructions of setting up facebook app as well. See if that helps.


Try This:

<?php
class page_fb extends Page {
    function init(){
        parent::init();    
        $f = $this->add("oauth/Controller_OAuth_Facebook");
        $fbtoken = $this->api->recall("fbtoken");
        if ($m = $_GET["error_msg"]){
            $v=$this->add("View_Error");
            $v->add("Text")->setHTML("You can't connect to the application.");
            $v->add("Button")->setHTML("Try again")->js("click", $this->js()->univ()->location("fb"));
            return;
        }
        if (!$fbtoken){
            if ($fbtoken = $f->check("email")){
                $this->api->memorize("fbtoken", $fbtoken);
                $this->api->redirect($this->api->url("/index"));
            }
        } else { 
            $f->setSignatureInfo();
            $f->setAuthToken($fbtoken["access_token"], $fbtoken["expires"]);

            $c = $this->add("sni/Controller_SNI_Facebook");
            $c->setOAuth($f);

            if (!$this->api->recall("fbuserinfo")){
                $this->api->memorize("fbuserinfo", $c->getUserProfile());
            }
            $info = $this->api->recall("fbuserinfo");
            $username = $info->username;
            $img = $c->customRequest("/" . $username . "/picture?type=large");
            $this->api->memorize("userimg", $img);
            $this->api->memorize("userinfo", $info);            

            if (!$this->api->auth->isLoggedIn()){
                $this->api->auth->login($info->email);
            }
            $this->api->redirect($this->api->url("/index"));
        }
    }
}
5
  • Nope, still doesn't work. It must be something with the app config on facebook's site. (I'm trusting this code is what you're using on the invest-game site?)
    – Will
    May 9, 2013 at 23:35
  • if you get 500 - it seems that you have php error on your server. check php error logs (enable logging if not done already)
    – jancha
    May 10, 2013 at 7:13
  • Dude, the error is from facebook's mobile server. If I could look at their error logs, I would have. If someone other than you made that comment, I would berate them for not having read the question :).
    – Will
    May 10, 2013 at 12:21
  • 1
    I apparently can't add images due to low reputation. I've added a link to a screen shot to the original question. A screen shot of the error itself is basically useless, so I've added a screenshot of the request, as per Chrome's dev tools network console.
    – Will
    May 10, 2013 at 14:18
  • created downloadable/explorable demo. check my answer.
    – jancha
    May 10, 2013 at 14:54
1

I've got the same problem, but using PHP: just using a mobile web browser is not working, giving '500 internal server error'.

I'm just asking myself if exists a parameter for the method getLoginUrl to force return a non-mobile version of the authentication page...

0

I reported this issue here: https://github.com/atk4/atk4-addons/issues/35

Please stay tuned and if you can, you can always make changes yourself and pull request. I can't test and fix this because strangely I still don't have smart phone :(

1
  • I cannot confirm this issue.
    – jancha
    May 9, 2013 at 10:03
0

Something changed in FB's mobile OAuth service that is causing the error. I ran a test with my code base on a shorter URL (ie; http://domain.net/fb/ rather than http://development.project.domain.net/fb) and it works fine. I am not entirely sure of what exactly is causing the problem as Facebook refuses to acknowledge the issue as being on their server, but I have a few possible culprits that may be triggering the error on their side, but since they don't care, I don't either, and I am providing my results for anyone else who encounters this bs.

  • The environment I am developing in uses semi-complex (apparently) naming scheme. The development server has its own hostname under a subdomain. The issue may be caused by the fact that there are multiple components to the host portion of the URL or simply too many characters.
  • The name servers for the development environment are provided by DynDNS. Facebook's mobile OAuth service may be choking on the idea of a development site being hosted on a non-permanent IP address.

I'm not going to do anymore testing on this because it really is a problem with Facebook, not my code or servers, and it will work in production.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.