Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Установка #1

Closed
dd3v opened this issue May 26, 2014 · 2 comments
Closed

Установка #1

dd3v opened this issue May 26, 2014 · 2 comments

Comments

@dd3v
Copy link

dd3v commented May 26, 2014

Здравствуйте. Подскажите, пожалуйста, как правильно установить модуль? Этот модуль только для "yii2-app-advanced" приложений?

@filsh
Copy link
Owner

filsh commented May 27, 2014

Нет, этот модуль можно поставить для любого yii2 приложения.
По пунктам:

  1. Выгрузить модуль в папку с модулями
  2. Применить миграцию
yii migrate --migrationPath=<путь к модулю>/migrations/m140501_075311_add_oauth2_server.php
  1. Настроить модуль в конфиге, у меня так
'modules.oauth2' => [
        'class' => 'filsh\yii2\oauth2server\Module',
        'options' => [
            'token_param_name' => \rest\base\HTTP::PARAM_ACCESS_TOKEN,
            'access_lifetime' => 3600 * 24
        ],
        'storageMap' => [
            'user_credentials' => 'common\p2s1\models\User'
        ]
    ]

common\p2s1\models\User - обычная модель реализующая интерфейс OAuth2\Storage\UserCredentialsInterface, таким образом данные о пользователе хранятся в нашей табличке
4. В контролере определить поведения, у меня так

use yii\helpers\ArrayHelper;
use yii\filters\auth\HttpBearerAuth;
use yii\filters\auth\QueryParamAuth;
use filsh\yii2\oauth2server\filters\ErrorToExceptionFilter;
use filsh\yii2\oauth2server\filters\auth\CompositeAuth;

class Controller extends \yii\rest\Controller
{
    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return ArrayHelper::merge(parent::behaviors(), [
            'authenticator' => [
                'class' => CompositeAuth::className(),
                'authMethods' => [
                    ['class' => HttpBearerAuth::className()],
                    ['class' => QueryParamAuth::className(), 'tokenParam' => \rest\base\HTTP::PARAM_ACCESS_TOKEN],
                ]
            ],
            'exceptionFilter' => [
                'class' => ErrorToExceptionFilter::className()
            ],
        ]);
    }
}

Этот модуль делался для себя, может для ваших целей он не подойдет. Что бы лучше понять как вообще оно работает нужно разбираться тут https://github.com/bshaffer/oauth2-server-php

@dd3v
Copy link
Author

dd3v commented May 27, 2014

Спасибо.

@dd3v dd3v closed this as completed May 27, 2014
jcherniak referenced this issue in pinfirestudios/yii2-oauth2-authorization-server Dec 25, 2019
ErrorToExceptionFilter crashes because of lack of getErrorMessage method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants