dicr / yii2-yandex-oauth

为Yii2提供的Yandex OAuth客户端

安装: 5

依赖: 0

建议者: 0

安全: 0

星标: 0

分支: 0

类型:yii2-extension

2.1.0 2021-04-09 07:59 UTC

This package is auto-updated.

Last update: 2024-09-09 10:38:49 UTC


README

API: https://yandex.ru/dev/oauth/doc/dg/concepts/about.html

手动获取调试令牌的方法,无需处理回调:https://yandex.ru/dev/oauth/doc/dg/tasks/get-oauth-token.html

此外,还实现了从Yandex.ID(Passport)API获取用户信息的方法 UserInfoRequest

配置

$config = [
    'components' => [
        'yandex-oauth' => [
            'class' => dicr\yandex\oauth\OAuthClient::class,
            'clientId' => 'ИД приложения',
        ]
    ]
];

使用方法

/** @var dicr\yandex\oauth\OAuthClient $oauth */
$oauth = Yii::$app->get('yandex-oauth'); 

/** @var dicr\yandex\oauth\AuthRequest $req запрос кода авторизации */
$req = $oauth->authRequest();

/** @var string $oauthUrl адрес для переадресации клиента */
$oauthUrl = $req->url();

// переадресация клиента на Яндекс.OAuth
Yii::$app->end(0, Yii::$app->response->redirect($oauthUrl));