nikitoktok/oauth2-yandex-id
最新稳定版本:v1.1.0
Composer 安装命令:
composer require nikitoktok/oauth2-yandex-id
包简介
Yandex ID provider for the PHP League OAuth2 Client
README 文档
README
Yandex ID provider for league/oauth2-client.
Installation
composer require nikitoktok/oauth2-yandex-id
Usage (Authorization Code)
<?php use Nikitoktok\Provider\Yandex; $provider = new Yandex([ 'clientId' => 'your-client-id', 'clientSecret' => 'your-client-secret', 'redirectUri' => 'https://example.com/oauth/callback', // Optional: override base URLs // 'baseUrl' => 'https://oauth.yandex.com', // 'resourceOwnerUrl' => 'https://login.yandex.ru/info', // Or use snake_case aliases: // 'base_url' => 'https://oauth.yandex.com', // 'resource_owner_url' => 'https://login.yandex.ru/info', ]); $authorizationUrl = $provider->getAuthorizationUrl([ // Example scopes: // 'scope' => ['login:info', 'login:email', 'login:avatar'], ]); $state = $provider->getState(); // Store $state in session and redirect to $authorizationUrl
After redirect:
<?php use League\OAuth2\Client\Provider\Exception\IdentityProviderException; // $_GET['state'] must match the stored $state // $_GET['code'] is returned by Yandex try { $accessToken = $provider->getAccessToken('authorization_code', [ 'code' => $_GET['code'], ]); $resourceOwner = $provider->getResourceOwner($accessToken); $yandexId = $resourceOwner->getId(); $email = $resourceOwner->getEmail(); $avatarUrl = $resourceOwner->getAvatarUrl(); } catch (IdentityProviderException $e) { // Error while fetching token or user info }
Endpoints
- Authorization URL:
https://oauth.yandex.com/authorize - Token URL:
https://oauth.yandex.com/token - User info:
https://login.yandex.ru/info?format=json
Notes
- User info requests are sent with the
Authorization: OAuth <token>header (the recommended method by Yandex).
Scopes / permissions
Yandex ID uses permissions (scopes) configured for the OAuth app.
Typical scopes seen in examples: login:info, login:email, login:avatar.
Verify the available permissions for your app in the Yandex console.
ResourceOwner helpers
getId()getLogin()getDisplayName()getFirstName()/getLastName()/getRealName()getEmail()/getEmails()getGender()/getBirthday()getDefaultPhone()getAvatarId()/getAvatarUrl()/isAvatarEmpty()getPsuid()toArray()
License
MIT
统计信息
- 总下载量: 42
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-03