GithubHelp home page GithubHelp logo

Установка about yii2-oauth2-server HOT 2 CLOSED

filsh avatar filsh commented on September 6, 2024
Установка

from yii2-oauth2-server.

Comments (2)

filsh avatar filsh commented on September 6, 2024

Нет, этот модуль можно поставить для любого 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

from yii2-oauth2-server.

dd3v avatar dd3v commented on September 6, 2024

Спасибо.

from yii2-oauth2-server.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.