Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
ninjauth setup
  • Has anyone successfully setup https://github.com/philsturgeon/fuel-ninjauth I added the package to the packages dir
    then set it load on startup in the config file
    'packages'  => array(
       'orm',
       'parser',
       'ninjauth',
       'auth'
      ),
    

    then created an auth controller in apps/classes/controller/auth.php
    with
    <?php
    class Controller_Auth extends \NinjAuth\Controller &#123;}
    

    then I test by going to:
    ..public/auth/session/facebook I get this error
    ErrorException [ Error ]: Class 'OAuth2\Provider' not found
    PKGPATH/ninjauth/classes/strategy/oauth2.php @ line 12
  • now I am getting this error:
    ErrorException [ Error ]: Class 'OAuth2\Exception' not found
    PKGPATH/oauth2/classes/exception.php @ line 12
    

    Any Ideas?????
  • Hi Harro, thanks for the reply. It's 1.3. Just downloaded the zip the other day - this is a completely new project. Just tried again, downloading the whole thing completely from scratch, with the same result. I'm guessing it must be something to do with MAMP not wanting to play nicely.
  • To clarify my steps and make sure I'm not missing anything: 1. Download latest Fuel and extract to target folder.
    2. Download Ninjauth package, extract to temp folder. Rename temp folder to ninjauth. Copy folder to fuel/packages (so it's in the same folder as parser, orm, auth, email etc. I haven't downloaded any additional packages.
    3. Enable auth and orm as always loaded packages in fuel/app/config/config.php
    4. Configure database connection in fuel/app/config/development/db.php and edit db.php to point at that named config.
    5. Start terminal, navigate to where oil lives, and run the commands: /Applications/MAMP/bin/php/php5.4.4/bin/php oil g migration create_users username:varchar[50] password:string group:int email:string last_login:integer login_hash:string profile_fields:text created_at:int /Applications/MAMP/bin/php/php5.4.4/bin/php oil refine migrate /Applications/MAMP/bin/php/php5.4.4/bin/php oil refine migrate --packages=ninjauth Does that sound reasonable? Other migrations work and I get tables created okay etc. I guess I can get moving by creating the tables etc manually, but as is perhaps apparent, I've not really used oil that much and want to use this project to learn to leverage it more effectively.
  • Fixed it - in 1.3, PKGPATH needs to be put back into package_paths in config.php so it looks like this: 'package_paths' => array(
    PKGPATH
    ), Explanation here: https://github.com/happyninjas/fuel-ninjauth/pull/32 Thanks for the help. :-)
  • I have a question regarding NinjAuth logic. In particular the logic after a callback uri from provider is called. At that time function login_or_register($strategy) gets executed in file strategy.php. In this function we have following check:
    if (\Auth::check())
    {
                list($driver, $user_id) = \Auth::instance()->get_user_id();           
                $num_linked = Model_Authentication::count_by_user_id($user_id);
                ...
    }
    
    // The user exists, so send him on his merry way as a user
    else if ($authentication = Model_Authentication::find_by_uid($user_hash['uid']))
    {
              ...
    

    I don't understand the logic here. Why would call Auth::check() at this point...? This will certainly always be false... At that time no user is logged and makes no sense calling Auth::check() here... Am I correct? And if a user is already logged in then you will never send him trough ninjauth authorization and the execution flow will never come up trough this code. What am I missing here?
  • I am trying to setup this Ninjauth but I am getting this error:
    Fuel\Core\FuelException [ Error ]: Listing columns failed, you have to set the model properties with a static $_properties setting in the model. Original exception: Database method Fuel\Core\Database_PDO_Connection::list_columns is not supported by Fuel\Core\Database_PDO_Connection
    PKGPATH/orm/classes/model.php @ line 249
    

    Any ideas? I have latest 1.1/master and uptodate ninjauth.
  • That has nothing to do with Ninjauth. You are using a database driver that doesn't support the list_columns() method. In that case, the ORM requires you do define the table properties in the model manually. See the documentation.
  • Harro Verton wrote on Tuesday 27th of December 2011:
    That has nothing to do with Ninjauth. You are using a database driver that doesn't support the list_columns() method. In that case, the ORM requires you do define the table properties in the model manually. See the documentation.

    i have the same problem.
    i use mysql
    Fuel\Core\FuelException [ Error ]: Listing columns failed, you have to set the model properties with a static $_properties setting in the model. Original exception: invalid data source name
    
    at location it works fine.
    on http://demo.mincms.com/ it is show that error.
    could you help
  • Harro Verton wrote on Tuesday 27th of December 2011:
    That has nothing to do with Ninjauth. You are using a database driver that doesn't support the list_columns() method. In that case, the ORM requires you do define the table properties in the model manually. See the documentation.
    Hello WanWizard. You were correct. I have passed this error and have come a long way since. Now I really cross up with a Ninjauth-related problem. Please see my comment (last one) in this Ninjauth blog post: http://philsturgeon.co.uk/blog/2011/09/ninjauth-social-integration-php. I am pasting the whole comment here as well. See below: I am trying to setup ninjauth with latest release of Fuel-PHP (1.1/master), and it doesn't seem to be working. I have setup all packages required for ninjauth: auth, oauth, oauth2, orm and all configuration needed for ninja auth. I am testing with Facebook login. I entered the right id and secret keys into ninjauth configuraiton. When I go to my site @ [url=http://localhost/fuel/public/auth/session/facebook,]http://localhost/fuel/public/auth/session/facebook,[/url] the ninjauth does show me registration site where the form data get's pulled from Facebook correctly. Clicking "submit" button does insert a new row into "users" table, but the insert into "authentications" table fails becuase insert values are null. Here is the complete error message:
    Fuel\Core\Database_Exception [ Error ]: SQLSTATE[23000]: Integrity constraint violation: 1048 Column
     'provider' cannot be null with query: "INSERT INTO `authentications` 
    (`provider`, `uid`, `access_token`, `secret`, `expires`, `refresh_token`, `user_id`, `created_at`, `updated_at`) 
    VALUES (null, null, null, null, null, null, '5', 1324988695, 1324988695)".
    

    Tracing back the error in ninjauth files I see the error happend in ninjauth/classes/controller.php, line 62. The array variable $user_hash doesn't have key $user_hash so most of the data passed to Authentications model is null:
    if ($user_id)
       &#123;
        Model_Authentication::forge(array(
         'user_id' => $user_id,
         'provider' => $user_hash['credentials']['provider'],
         'uid' => $user_hash['credentials']['uid'],
         'token' => $user_hash['credentials']['token'],
         'secret' => $user_hash['credentials']['secret'],
         'created_at' => time(),
        ))->save();
       }
    

    Then I went debugging and dumped $user_hash array to see what is in it I get the following output:
    array(8) &#123; ["uid"]=> string(9) "668244746" ["nickname"]=> string(10) "primozrome" ["name"]=> string(11) "Primoz Rome" ["email"]=> string(17) "primozr@gmail.com" ["location"]=> NULL ["description"]=> NULL ["image"]=> string(164) "https://graph.facebook.com/me/picture?type=normal&access_token=AAACl59bsWg8BAHWAZA6ZARmcZBxxXWIsACSZBb5FD02TrDco8j2AkkN4tslRK2uXjH0R2FtKKyfyMylNZCZCDQTlFksmZB0XBsZD"; ["urls"]=> array(1) &#123; ["Facebook"]=> string(34) "http://www.facebook.com/primozrome"; } }
    

    As seen from this dumb $user_hash indeed does not have $user_hash key as controller.php assumes in line 62. Is there anything I am doing wrong or is there a bug in Ninjauth?
    Thanks and best regards,
    Primoz
  • This is something Phil has to look at. I haven't used it, so I can't comment on it's internal workings...
  • Harro Verton wrote on Tuesday 27th of December 2011:
    This is something Phil has to look at. I haven't used it, so I can't comment on it's internal workings...

    Thanks Wiz. I already got email from Phil, and we are trying to find solution. I will post findings up here, might be useful to someone else...
  • Looks like you're using an other version of FuelPHP than 1.2, and you're using the PDO driver. The PDO driver only has list_columns() support as for version 1.2.
  • If I send a logged in user to /social/session/facebook I can add it to their existing user, instead of always assuming somebody is trying to log in or register.
  • first copy the folder "philsturgeon-fuel-ninjauth-######" to you fuel/packages directory. rename it to ninjauth open your fuel/app/config/config.php
    -- find the auto loader array for packages and add these to the array ninjauth, oauth, oauth2, orm and auth
    which will give you this
    'packages'  => array(
       "ninjauth","oauth","oauth2","orm","auth"
      ),
    
    now to the command line and run this
    oil refine migrate --packages=ninjauth
    
    && to be safe
    oil refine migrate
    

    now open fuel/packages/ninjauth/config/ninjauth.php and add your keys create your controller
    class Controller_Auth extends NinjAuth\Controller &#123;}
    

    visit http://www.testsite.com/auth/session/twitter and you should be on your way :)
  • Use JavaScript if you want to mess with tabs or windows.
  • I am trying to get Facebook Auth dialog open in a new popup browser window, instead in same window. When callback is made I want that to be called in the same browser window where user clicked login button. Does anyone know how to achieve this? By default ninjauth will open in same window. Usually Facebook auth dialog is shown in popup window and then after user accepts login he is returned back to his previous window.
  • I'm sure it's because I'm being an idiot, but I can't get this to work following Phil's instructions here: http://philsturgeon.co.uk/blog/2011/09/ninjauth-social-integration-php Have downloaded ninjauth from Github, and extracted it to fuel/packages/ninjauth. I've added ninjauth, auth, oauth, oauth2, and orm to my packages array in config.php. I've created a database table that contains all the necessary fields (as well as a number of other fields). When I try and run the migrations in the package to create the authentications table, I get: Error: Undefined variable: files in /Users/tom/Sites/mysite/fuel/core/classes/migrate.php on 528 Any suggestions most welcome. Sorry if I'm missing something obvious - the only packages I've used to this point have been auth and email, so I haven't had to do much to get them working.
  • Which version of Fuel are you on? That looks like an error that has been fixed some time ago.

Howdy, Stranger!

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

In this Discussion