Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Opauth with GoogleStrategy
  • Until I have to report the potential bug regarding the opauth google driver, as I already told you, if I don't set a path in app/config/opauth.php, when I access the controller to login with Facebook let's say ( http://kbx3.de/CMS-Sites/funding_funnel/account/oauth/facebook )  I receive the error  :

    Fuel\Core\PhpErrorException [ User Error ]: Unsupported or undefined Opauth strategy - CMS-Sites



    DOCROOT/fuel/vendor/opauth/opauth/lib/Opauth/Opauth.php @ line 120



    115                    $this->env['params']['action'] = 'request';
    116                }
    117                
    118                $this->Strategy->callAction($this->env['params']['action']);
    119            } else {
    120                trigger_error('Unsupported or undefined Opauth strategy - '.$this->env['params']['strategy'], E_USER_ERROR);
    121            }
    122        } else {
    123            $sampleStrategy array_pop($this->env['Strategy']);
    124            trigger_error('No strategy is requested. Try going to '.$this->env['complete_path'].$sampleStrategy['strategy_url_name'].' to authenticate with '.$sampleStrategy['strategy_name'], E_USER_NOTICE);
    125        }

    Backtrace



    1. COREPATH/bootstrap.php @ line 79


    2. DOCROOT/fuel/vendor/opauth/opauth/lib/Opauth/Opauth.php @ line 120


    3. DOCROOT/fuel/vendor/opauth/opauth/lib/Opauth/Opauth.php @ line 88


    4. APPPATH/classes/controller/account.php @ line 617


    5. COREPATH/classes/request.php @ line 440


    6. DOCROOT/index.php @ line 54
    So the problem is that the segments are still there, even if I make the update as you suggested. If I put the paths, it works for facebook, twitter and linkedin, but not for google...

  • In your index.php, can you do a var_dump($_SERVER) when you do the initial request for your URL, and post that on http://bin.fuelphp.com (or email it to wanwizard<at>fuelphp.com)?

    I can not come up with a scenario in which the FIRST segment will be seen as the strategy...

    Where (in which folder) is your index.php? What kind of rewriting rule are you using, and where is it defined (if in .htaccess, in which folder is the .htaccess)?
  • Done, I've sent you an email with everything you've asked. Thanks
  • Found it, but I don't see anything strange.

    I've setup a test application (using our app framework for which I've designed Auth/Opauth) in a similar folder structure (here "opauth/funding_funnel").

    I've added this to the opauth.php configuration file:

            'Google'            => array(
                'client_id'     => '***********.apps.googleusercontent.com',
                'client_secret' => ''***********',
            ),

    after which the login button for Google appeared on the login page. When I click on it, it redirects to Google without problems.

    I can't test the callback at the moment, since I'm on a .local domain, but Google reports the callback URL to be

    redirect_uri=http://fuelphp.catwoman.exite.local/opauth/funding_funnel/login/session/google/oauth2callback

    Which is correct.

    So I'm still clueless...
  • So my first question is how is it possible to not receive the same error message when you call a provider.

    If I fire in browser (without setting a path in opauth.php config file) : http://kbx3.de/CMS-Sites/funding_funnel/account/oauth/facebook
    I receive the error :
    Fuel\Core\PhpErrorException [ User Error ]: Unsupported or undefined Opauth strategy - CMS-Sites

    so normally when you fire in browser : http://fuelphp.catwoman.exite.local/opauth/funding_funnel/login/session/google you should receive the error :
    Fuel\Core\PhpErrorException [ User Error ]: Unsupported or undefined Opauth strategy - opauth (the segment before funding_funnel)

    If I set the path, the problem is exact the Google callback.

    I
    can also reach the login page, I authorize the app, and it redirects me
    back to oauth2callback ... but should be redirected to the callback not oauth2callback , the same for all strategies...or not ?

    Because in my login controller i don't have an oauth2callback method but a callback one, for all...see this example.

    Even
    if I had an oauth2callback method what should contain for google, which
    respond with an code like this ( http://kbx3.de/CMS-Sites/funding_funnel/account/oauth2callback/?code=4/ezzWUALwjwzJfaNEBVTLdRHQgBCC.slNg1_IOzlMZOl05ti8ZT3YdsRrXfwI ) to manually call the methods from inside the
    GoogleStrategy.php class, in order to get the access token and then to call another method to get user info's ??

    Do you have an controller example which takes care of Google and at least another one provider (Facebook or Twitter or ...) ? I wanna see how your callback(s) looks, to understand what I'm doing wrong...

    Where is the mistake ? :(

  • Very good question. the answer is I don't know.

    If you're willing to, you can make a zip of your entire funding_funnel folder, do me a zip with a database dump (if needed to start), and I'll try to setup your code here and see if I can reproduce it.

    Other then that, I'm out of idea's.
  • My controller looks exactly like the example in the docs. The example is taken of our app framework auth controller, I only removed the bits specific to our environment, like for example message handling.
  • Done, I've emailed you the entire project and the DB dump. Many thanks for the professional support.
  • Hmmm, is to big ... i transfer it now through www.transfer.ro. You will receive an email with a link to download it.Thanks
  • No problem, I hate not knowing why as much as you do... ;)
  • HarroHarro
    Accepted Answer
    Just installed it, and already found it.

    Where did you get the idea from that you can do:

    $opauth = new Opauth($this->_config, true);   

    and get it to work?

    This is not a plain PHP Opauth setup, this is a FuelPHP Auth controller. Which means you need to use the Auth_Opauth class that is provided in the Auth package, and that gives you the interface between the native Opauth classes and the Auth package.

    Your code however looks like a plain Opauth setup, which is never going to work, due to the way FuelPHP uses the URI. Also, there will be no Auth integration, you need to do everything yourself.

    The example in the docs (http://docs.fuelphp.com/packages/auth/examples/opauth.html) clearly states in the login block you need to use

    \Auth_Opauth::forge();

    to initiate an Oauth login.

    The callback method is even worse. Please have a look at the example again, you can use that code as-is.

    And as a side note: In general, NO Fuel class is instantiated using "new", so that should have been your first give-away you're doing the wrong thing.
  • Now I understand what was going on. It was a terrible mistake, because I start with this example from here and from there it escalated...

    Now I've create a subdomain : http://venturate.kbx3.de, where I've installed the project. Now I just have to call like this: http://venturate.kbx3.de/account/oauth/facebook, and it comes back and the callback function parses the response. The same for Twitter and Linkedin, but again the problem with Google.

    Which is the redirect_uri that I have to set on Google Apis Console ?

    Is not : http://venturate.kbx3.de/account/callback/

    because like this I have it on Linkedin and Twitter and it works ?

    If I set it as : http://venturate.kbx3.de/account/callback/, when I click to authenticate with google, I receive this message :

    Error: redirect_uri_mismatch

    The
    redirect URI in the request:
    http://venturate.kbx3.de/account/oauth/google/oauth2callback did not
    match a registered redirect URI

    Learn more

    Request Details

  • Done,
    I've changed the uri_redirect on the Google APIs Console like this :
    http://venturate.kbx3.de/account/oauth/google/oauth2callback and it finally worked.

    Many thanks for your support, and hopefully this discussion will help other novices like me, to better understand how should they do it.

    I think it will be a good idea to say somewhere in the documentation that the uri_redirect for google MUST be set like above, because for others providers it was ok with http://venturate.kbx3.de/account/callback/
  • Can you create an issue for that on https://github.com/fuel/auth/issues so someone can pick that up?
  • Thanks!
  • I've looked at it again, and I still believe you're doing it different then in the example.

    Both 'int_callback' and 'oauth2callback' are INTERNAL methods of the Opauth drivers, they should and are not exposed in the case of the Auth package.

    All callbacks have to go to the action_callback method in your controller, it will initialize the Opauth class and then call it's internal callback processing method, it doesn't use Opauth's standard processing for that.
  • Perhaps to clarify, the internal callback is constructed by the Opauth driver, and unfortunately not very consistent amongst drivers.

    Whether or not that is a problem depends on the service. Google seems to want a complete and precise list of callback URI's, while Facebook accepts every URL in one of the app domains.

    It's a bit difficult for us to document the idiosyncrasies of the individual Opauth drivers. No clue why the developer chose "int_callback" in one case, "oauth2callback" in another...
  • I've opened an issue with Opauth to get them to unify the callback method of all supported Strategies.

    I think that is a better approach then us documenting the anomalies...
  • Good Idea..it must be Opauth side in my opinion too.
  • Hi Harro,

    I've received an message that says the Issue has been closed, and your message : 'Done'. How has been solved ? I didn't found anything new in documentation (or I miss it) .... or there is an update of the Auth Package .. or the Opauth package (through Composer) was renewed ... or ?

    Thanks.
  • Changes always happen in the develop branch, we never change a master branch, unless we release a maintenance or minor release for which development stuff is backported.

    In case of docs, you can find the development version here: http://dev-docs.fuelphp.com

    Done refers to the request in the issue, which was to amend the documentation.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion