movemoveapp/vkid
Composer 安装命令:
composer require movemoveapp/vkid
包简介
VK ID OAuth 2.1 (id.vk.ru) Socialite provider with PKCE (cache-based, stateless-friendly).
README 文档
README
composer require movemoveapp/vkid
Register an application
Create a new VK ID application at id.vk.ru. Make sure you specify the correct redirect URI (must match exactly with the one in your config).
Installation & Basic Usage
Please see the Base Installation Guide first, then follow the VK ID-specific instructions below.
Add configuration to config/services.php
'vkid' => [ 'client_id' => env('VKID_CLIENT_ID'), 'client_secret' => env('VKID_CLIENT_SECRET'), 'redirect' => env('VKID_REDIRECT_URI'), // --- Extended configuration --- 'scopes' => env('VKID_SCOPES', ['email']), // default: ['email'], supports ['email','phone'] 'pkce_ttl' => env('VKID_PKCE_TTL', 10), // minutes to store code_verifier 'cache_store' => env('VKID_CACHE_STORE', 'redis'), // cache store for PKCE verifier 'cache_prefix' => env('VKID_CACHE_PREFIX', 'socialite:vkid:pkce:'), 'api_version' => env('VKID_API_VERSION', '5.199'), // VK API version ],
Add provider event listener
Laravel 11+
Since Laravel 11 removed EventServiceProvider, use the Event facade in your AppServiceProvider@boot:
use Illuminate\Support\Facades\Event; use SocialiteProviders\Manager\SocialiteWasCalled; use MoveMoveApp\VKID\VKIDExtendSocialite; public function boot(): void { Event::listen(SocialiteWasCalled::class, [VKIDExtendSocialite::class, 'handle']); }
Laravel 10 or below
Add the listener in your `app/Providers/EventServiceProvider.php`. See the [Base Installation Guide](https://socialiteproviders.com/usage/) for detailed instructions.protected $listen = [ \SocialiteProviders\Manager\SocialiteWasCalled::class => [ MoveMoveApp\VKID\VKIDExtendSocialite::class.'@handle', ], ];
Usage
You can now use the driver as usual with Socialite:
return Socialite::driver('vkid')->redirect();
For extended scopes (e.g. apps with Business Account permission):
return Socialite::driver('vkid') ->scopes(['email', 'phone']) ->redirect();
Handling the callback:
try { $vkUser = Socialite::driver('vkid')->user(); // Typical fields: // $vkUser->getId(), getNickname(), getName(), getEmail(), getAvatar() // Optional phone (if scope=phone and app has permission): // $vkUser->user['phone'] ?? null // Your app logic: $localUser = User::firstOrCreate( ['email' => $vkUser->getEmail() ?? "vk_{$vkUser->getId()}@example.local"], ['name' => $vkUser->getName()] ); Auth::login($localUser); return redirect()->intended('/'); } catch (\Laravel\Socialite\Two\InvalidStateException $e) { // Thrown when PKCE verifier expired (user waited too long) return redirect()->route('login')->with('auth_error', 'Authorization expired. Please try again.'); } catch (\RuntimeException $e) { // Thrown when cache store is unavailable/misconfigured report($e); return redirect()->route('login')->with('auth_error', 'Temporary VK ID authorization error.'); } catch (\Throwable $e) { report($e); return redirect()->route('login')->with('auth_error', 'Unexpected VK ID login error.'); }
Returned User fields
| Field | Description |
|---|---|
id |
VK user ID |
nickname |
screen_name (if present) |
name |
First + last name |
email |
from id_token (if scope=email) |
avatar |
URL to 200px profile photo |
phone |
from id_token (if scope=phone and granted) |
Exception Reference
| Exception | Cause | Recommended handling |
|---|---|---|
Laravel\Socialite\Two\InvalidStateException |
- state or PKCE verifier missing or expired- user waited longer than pkce_ttl minutes before pressing “Allow” | Ask user to restart login. Show message like “Authorization expired. Please try again.” |
RuntimeException("VKID PKCE cache failure") |
Cache store misconfigured or unavailable (e.g., Redis down) | Log and retry later. Typically a server-side infra issue. |
RuntimeException("VKID PKCE cache failure: unable to persist code_verifier") |
Misconfigured cache_store or permission issue writing PKCE state | Ensure correct cache driver in config/cache.php |
Any other exception |
Networking or unexpected JSON format | Generic fallback “VK ID login failed” |
All exceptions extend base \Throwable and can be caught globally in your app’s Handler.
Extended Configuration Options
| Key | Type | Default | Description |
|---|---|---|---|
| `client_id | string | – | VK App ID |
| `client_secret | string | – | VK App secret |
| `redirect | string | – | Full callback URL (must match app settings) |
| `scopes | array | ['email'] | Default OAuth scopes |
| `pkce_ttl | int | 10 | Time in minutes to store PKCE verifier |
| `cache_store | string | 'redis' | Cache store for PKCE (see config/cache.php) |
| `cache_prefix | string | 'socialite:vkid:pkce:' | Prefix for PKCE keys |
| `api_version | string | '5.199' | VK API version for users.get |
Example .env
VKID_CLIENT_ID=1234567 VKID_CLIENT_SECRET=secretkey VKID_REDIRECT_URI=https://your-app.com/auth/vkid/callback VKID_SCOPES="['email','phone']" VKID_PKCE_TTL=10 VKID_CACHE_STORE=redis VKID_CACHE_PREFIX=socialite:vkid:pkce: VKID_API_VERSION=5.199
Example User Flow Diagram
Client → https://id.vk.ru/authorize?response_type=code&state=XYZ...
↳ Redirects user back to /auth/vkid/callback?code=...&state=XYZ
Provider → Exchanges code for tokens (with code_verifier)
↳ Fetches user profile via api.vk.com/method/users.get
App → Creates/logs in user, handles avatar/email/phone sync
Reference
movemoveapp/vkid 适用场景与选型建议
movemoveapp/vkid 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.41k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2025 年 10 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「oauth」 「sdk」 「laravel」 「vk」 「pkce」 「movemove」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 movemoveapp/vkid 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 movemoveapp/vkid 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 movemoveapp/vkid 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
WeChat OAuth SDK
Ory-Hydra OAuth 2.0 Client Provider for The PHP League OAuth2-Client
Library for ORCID web services
A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.
Alfabank REST API integration
OAuth 2.0 资源服务器扩展插件
统计信息
- 总下载量: 2.41k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-10-15