PHPackages                             sleepwalker/hoauth - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. sleepwalker/hoauth

AbandonedArchivedLibrary

sleepwalker/hoauth
==================

v1.2.5(11y ago)5932535[13 issues](https://github.com/SleepWalker/hoauth/issues)[1 PRs](https://github.com/SleepWalker/hoauth/pulls)PHP

Since Sep 9Pushed 8y ago16 watchersCompare

[ Source](https://github.com/SleepWalker/hoauth)[ Packagist](https://packagist.org/packages/sleepwalker/hoauth)[ RSS](/packages/sleepwalker-hoauth/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (3)Used By (0)

hoauth v1.2.5
=============

[](#hoauth-v125)

- `hoauth` extension provides simple integration with social network authorization lib [Hybridauth](http://hybridauth.sourceforge.net/) in Yii. (facebook, google, twitter, vkontakte and much more).
- Automatically finds and supports `yii-user` module ([instruction for yii-user](https://github.com/SleepWalker/hoauth/wiki/%5Binstall%5D-hoauth-and-yii-user-extension)).
- supports prefixed tables
- Supports I18N ([available translations](https://github.com/SleepWalker/hoauth/tree/master/messages))

\###[Demo](http://hoauth.hamstercms.com/yii-user/) | [Demo Source Code](https://github.com/SleepWalker/hoauth-demo-site)

Requirements
------------

[](#requirements)

- Yii 1.1.9 or above. (I have tested it only in 1.1.13)

Available social networks
-------------------------

[](#available-social-networks)

- OpenID
- Google
- Facebook
- Twitter
- Yahoo
- MySpace
- Windows Live
- LinkedIn
- Foursquare
- Vkontakte
- AOL

Additional social networks providers can be found at HybridAuth [website](http://hybridauth.sourceforge.net/download.html). And how to configure them [here](http://hybridauth.sourceforge.net/userguide.html) at the bottom of the page.

A little about how it's woks
----------------------------

[](#a-little-about-how-its-woks)

The users of `yii-user` extension can skip this section, because `hoauth` will do all the stuff automatically. This extension authenticates and if it's need creates new user. When user was registered "locally" (so he has login (email) and password), then he can also log in with it's social account (extension checks if user with provided email exists in db, when yes, the he will be logged in and it is no matter how had he registered earlier - locally or not). After the user logged in he will be redirected to `Yii::app()->user->returnUrl`.

This extension requires `UserIdentity` class, but doesn't use `authenticate()` method of `UserIdentity` class. Class constructor called with parameters `new UserIdentity($mail, null)` and than called `CWebUser::login()` method (while authentication work did for us social network). When social network didn't give us user's email, the **hoauth** will ask user for email, when email exists in our db, the password will be asked too. At the end we bind provided by social network unique user identifier to user id for future sign in. [Example of UserIdentity class](https://github.com/SleepWalker/hoauth/wiki/UserIdentity-class-example).

If you need to perform some access check for user, you can use `hoauthCheckAccess($user)` callback (simply create new method in controller where you added `HOAuthAction`). This method will be called with one input argument - *User model* of the user being authorized. This method should return integer values (`accessCode`) depending on the scenario needed:

- 0 - user shouldn't get access
- 1 - user may login
- 2 - user may login, but not now (e.g. the email should be verified and activated) You can also not only return the `accessCode`, but also render the page with error or any information you need.

**NOTE:** This extension will also automatically create `user_oauth` table in your database. About it see "`UserOAuth` model" section.

Installation and Usage
----------------------

[](#installation-and-usage)

- [instruction for yii-user](https://github.com/SleepWalker/hoauth/wiki/%5Binstall%5D-hoauth-and-yii-user-extension)

**1.** Make `hoauth` directory in your `extensions` directory (or in any other directory you want) and copy the content files there. Directory structure example:

```
/protected/
   extesions/
      hoauth/
         hybridauth/
         messages/
         models/
         views/
         widgets/
         .gitignore
         CHANGELOG
         DummyUserIdentity.php
         HOAuthAction.php
         HOAuthAdminAction.php
         MIT-LICENSE.txt
         README.md
         UPGRADE.md
```

**2.** Edit your controller source code (eg. `SiteController` class with `actionLogin()` method) to add new actions:

```
class SiteController extends Controller
{
	/**
	 * Declares class-based actions.
	 */
	public function actions()
	{
		return array(
      'oauth' => array(
        // the list of additional properties of this action is below
        'class'=>'ext.hoauth.HOAuthAction',
        // Yii alias for your user's model, or simply class name, when it already on yii's import path
        // default value of this property is: User
        'model' => 'User',
        // map model attributes to attributes of user's social profile
        // model attribute => profile attribute
        // the list of avaible attributes is below
        'attributes' => array(
          'email' => 'email',
          'fname' => 'firstName',
          'lname' => 'lastName',
          'gender' => 'genderShort',
          'birthday' => 'birthDate',
          // you can also specify additional values,
          // that will be applied to your model (eg. account activation status)
          'acc_status' => 1,
        ),
      ),
      // this is an admin action that will help you to configure HybridAuth
      // (you must delete this action, when you'll be ready with configuration, or
      // specify rules for admin role. User shouldn't have access to this action!)
      'oauthadmin' => array(
        'class'=>'ext.hoauth.HOAuthAdminAction',
      ),
		);
	}
}
```

**3.** Add the `findByEmail` method to your user`s model class:

```
  /**
   * Returns User model by its email
   *
   * @param string $email
   * @access public
   * @return User
   */
  public function findByEmail($email)
  {
    return self::model()->findByAttributes(array('email' => $email));
  }
```

**4.** Visit your `oauthadmin` action (eg. ) to create the HybridAuth config. For your `HybridAuth Endpoint URL` use this: . After install you can leave `install.php` in your file system, while it's in Yii protected directory. But you must **remove** `oauthadmin` action, or make such rules, that give access only for admin users. Config file can be found at `application.config.hoauth`

**5.** Add social login widget to your login page view (you can use `route` property, when you placing your widget not in the same module/controller as your `oauth` action):

```
