D
D
Dilik Pulatov2020-02-06 13:45:24
Yii
Dilik Pulatov, 2020-02-06 13:45:24

How to set a custom identity class for each module in Yii2?

Good afternoon
I have two RestAPI modules api1, api2
and each has its own authorization model.
How to make it so that when requesting to the api, each module uses its own authorization model to find the user by the token?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim, 2020-02-07
@dilikpulatov

You are strange. Why do you need such a garden?

  1. If you have 2 different apis and you don't interact with them using common authorization data, separate them into 2 applications.
  2. If you have 2 different apis using common authorization data, make them either folders in one application, or two different ones with cross-site authorization.

D
Dmitry Kim, 2020-02-06
@kimono

Similar to how you do it in the main app:

'user' => [
    'identityClass' => 'common\models\User',
    'loginUrl' => '/site/login',
    'identityCookie' => [
        'name' => '_identity-frontend',
    ],
],

Those. more or less like this:
'modules' => [
    'api1' => [
        'class' => 'api\modules\Api1',
        'components' => [
             'user' => [
                'identityClass' => 'common\models\Api1User',
                'loginUrl' => '/site/login',
                'identityCookie' => [
                    'name' => '_identity-api1',
                ],
            ],
        ]
    ],
    'api2' => [
        'class' => 'api\modules\Api2',
        'components' => [
             'user' => [
                'identityClass' => 'common\models\Api2User',
                'loginUrl' => '/site/login',
                'identityCookie' => [
                    'name' => '_identity-api2',
                ],
            ],
        ]
    ],
]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question