[MODULE] HybridAuth

I’m a newbie to Yii but reasonably experienced in general OOP development, and it sounds odd to me. The OOP idea of classes extending each other is that they are related. eg


class Dog extends Mammal 

A Controller extending a Module is different to this principle, or even the base controller extending a modules controller is upside down. Bit more like:


class Fish extends Dog 

:lol:

If all you want is the class functions to be available to all controllers, why not just do


Yii:app->getModule()->...

in your controllers?

I haven’t got to behaviours yet in my reading so I won’t say anything more!

Please hare it on Github

Upside down, how?

A controller is a controller, no matter where it is.

However, by letting a module depend on the user extend from a base controller (from the module) is problematic if the user has several extensions which depends on it.

Behaviors and filters, on the other hand, can be chained together, which is why I think it’s better.

You raised the question yourself: What if several modules wants you to make use of a base controller provided by them?

If all you want is to use a component or two in your already existing auth handling code, then that’s perfect and non-intrusive.

And I personally want YiiAuth/HybridAuth to provide that option.

Because I already have a working set of WebUser/WhatEver and I only need to call HybridAuth related functions, so I don’t need any convenience classes/functions.

Well with yii auth I have all I need, I can update statuses, login users, access info etc.

Actually it’s more then I need, but I would love to help the yii community because social integration is extremely popular. And if I can help yii fight vs zend/cakePhp/codeigniter/symfony2 I will :P

That is my only goal.

You two seem to be better then me about yii functions/methods etc.

And you seem to got this covered, if you want my help please pm me and I’ll do my best.

Currently 90% of my work is jquery stuff, so anything, please ask for help:)

Glad to see this conversation heading in the right direction! Thanks for all the work you’ve done already guys.

I’ll interject my “requirements” here as well…I think the combo approach sounds the best to me also.

Key points: easily updateable, easy to integrate, multiple provider associations

As implemented, the YiiAuth method of extending the base controller definitely feels a little unnatural, but I don’t have enough experience to know exactly why. Something less intrusive would seem to be a much better fit - maybe follow the model of some other extensions (yii-user, YUM)? I also don’t see why it is necessary to extend the controller, as not every controller/action will need access to the hybrid auth methods. (that being said, I followed Sampa’s instructions, and getting it working was really quite simple)

I think the extra table to store provider associations is absolutely necessary as well - this is the model that is recommended by other frameworks as well as services like janrain, gigya…etc.

Something as important as this (IMO) would benefit from the input of key players - Qiang, Samdark, mdomba…etc, as this type of extension will be exactly what people are looking for when they start to look for a new development framework.

You point out many important things. I have been queastionig the approach yiiauth has after reading what jacmoe and markvr has written. I guess it comes down to me not knowing enough about yii. I could do alot jquery style, aslong as someone told we what I should do, what would improve hybridauth for the yii framework.

So, is this going to be put up on Bitbucket or Github? :)

Would make it much easier to contribute/collaborate by means of forks, pull requests, patch queues, etc.

Nice module and nice features but it can be even more better by making some internet merchant account improvements.

Hi Guys, I’ve just come to have a look at using this module, but it would appear that the upload of the hosted file has gone wrong, it’s showing as 0.0kb for me.

same problem - could you please fix that? thanks, nils

So it has, how odd. Reuploaded and OK now.

Will do when I’ve got Netbeans to work with the Git plugin…doesn’t want to install at the moment…

The NetBeans team uses Mercurial so that definitely works - use Mercurial and Bitbucket, then. :)

Thanks alot, I’m gonna have a play around with this now.

Thanks for the addon. Can you explain how I could integrate this with Yii-User please? Sorry, I’m a bit noob. I get to login from a provider, then I get redirected to the createUser view


Call to a member function getAttributes() on a non-object in /home/something/protected/modules/user/components/WebUser.php

Which refers to this:


    public function updateSession() {

        $user = Yii::app()->getModule('user')->user($this->id);

        $userAttributes = CMap::mergeArray(array(

                                                'email'=>$user->email,

                                                'username'=>$user->username,

                                                'create_at'=>$user->create_at,

                                                'lastvisit_at'=>$user->lastvisit_at,

                                           ),$user->profile->getAttributes());

        foreach ($userAttributes as $attrName=>$attrValue) {

            $this->setState($attrName,$attrValue);

        }

    }



That would be great to have a tutorial on how to integrate this wonderful addon with yii-user.

Thanks!

I think it’s because YiiUser replaces the User model (which extends CActiveRecord) with a Component, and that doesn’t contain the method getAttributes.

So when you do:


$user = new User;

in HybridAuth you get the User component rather than model.

YiiUser does still have a User class that extends CActiveRecord though, so it depends how Yii’s autoloaded resolves the classes.

I think that’s what’s going on anyway. If anyone has a better idea let me know!

The above is wrong, I think it’s probably because you’re not creating a profile at the same time as the user model.

A working version with multiple providers and support for YiiUser is up at https://github.com/markvr/hybridauth

It needs improving and more testing before updating the Yii exentension but if anyone is desperate for these features now then it’s a start.

YiiUser Support:

You must have either NO config entries for YiiUser AND HybridAuth:withYiiUser config entry == false, OR the opposite.

i.e. what you mustn’t do is HybridAuth:withYiiUser==false and also some config entries (e.g. imports etc) for YiiUser or vice versa. It will screw the autoloading up.

To use it with YUM, you end up needing to use the register() method, which will register the user and create an assocated profile (a blank profile if no attributes are designated in the call to register(). My guess is that it is similar for Yii-User.

you’ll need a new table as well:


CREATE TABLE IF NOT EXISTS `ha_logins` (

  `id` int(11) NOT NULL AUTO_INCREMENT,

  `userId` int(11) NOT NULL,

  `loginProvider` varchar(50) NOT NULL,

  `loginProviderIdentifier` varchar(100) NOT NULL,

  PRIMARY KEY (`id`),

  UNIQUE KEY `loginProvider_2` (`loginProvider`,`loginProviderIdentifier`),

) ENGINE=InnoDB  ;

etc