PHPackages                             stiks/yii2-eveonline-sso - 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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. stiks/yii2-eveonline-sso

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

stiks/yii2-eveonline-sso
========================

OAuth2 client for EveOnline SSO

080PHP

Since Feb 21Pushed 9y ago2 watchersCompare

[ Source](https://github.com/stiks/yii2-eveonline-sso)[ Packagist](https://packagist.org/packages/stiks/yii2-eveonline-sso)[ RSS](/packages/stiks-yii2-eveonline-sso/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (1)Used By (0)

Yii2 EveOnline SSO OAuth2 client extension
==========================================

[](#yii2-eveonline-sso-oauth2-client-extension)

This extension uses standart `yii2-authclient` to allow auth via EveOnline site. Based on `unti1x/yii2-eveonline-sso`

Dependencies
------------

[](#dependencies)

The only required package is `yiisoft/yii2-authclient` version "2.1+"

Installation
------------

[](#installation)

### Via Composer

[](#via-composer)

Add line `"stiks/yii2-eveonline-sso": "*"` in your `composer.json` into `require`-section and then update packages

### Via Console

[](#via-console)

Use following command:

```
composer require "stiks/yii2-eveonline-sso" "dev-master"
```

Usage
-----

[](#usage)

Configuration, config/web.php:

```
'components' => [

    # ...

    'authClientCollection' => [
        'class' => 'yii\authclient\Collection',
        'clients' => [
            'eve-online-sso' => [
                'class' => 'stiks\eveonline_sso\EveOnlineSSO',
                'clientId' => 'Your Client ID',
                'clientSecret' => 'Your Client Secret',
                'scope' => [
                    # your scope here
                    'characterAccountRead'
                ]
            ],
        ],
    ]

    # ...

]
```

You can also add some fields into `User` model, like `character_id`, `character_name`, `owner_hash`. The last one is strongly recomended because characters can be transfered to another account and CCP provides a way to check this with unique code (see SSO manual, "Obtain the character ID" section).

Next register `auth` action in a controller:

```
    public function actions () {
        return [
            'auth' => [
                'class' => 'yii\authclient\AuthAction',
                'successCallback' => [$this, 'successCallback'],
            ],
        ];
    }
```

And implement `successCallback`-method that should be called on user successfully authorized.

You can use something like this:

```
    public function successCallback ($client) {
        $attributes = $client->getUserAttributes();

        if (Yii::$app->user->isGuest) {
            # get user by hash
            $user = User::findOne (['owner_hash' => $attributes['CharacterOwnerHash']]);
            if($user) {
                Yii::$app->user->login ($user);

                return $this->->goHome ();
            }

            # new user found
            $user = new User ();
            $user->attributes = [
                  'character_id'   => $attributes['CharacterID'],
                  'character_name' => $attributes['CharacterName'],
                  'owner_hash'     => $attributes['CharacterOwnerHash']
            ];
            if (!$user->save ()) {
                Yii::error (print_r ($user->getErrors (), true));
            }

            Yii::$app->user->login ($user);
        }

        return $this->->goHome ();
    }
```

Example code for views:

```
