PHPackages                             max-lit/oauth2-vkontakte - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. max-lit/oauth2-vkontakte

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

max-lit/oauth2-vkontakte
========================

Vkontakte provider for league/oauth2-client

1.1.1(9y ago)0448MITPHPPHP &gt;=5.5

Since Mar 28Pushed 4y agoCompare

[ Source](https://github.com/MaksimLit/oauth2-vkontakte)[ Packagist](https://packagist.org/packages/max-lit/oauth2-vkontakte)[ RSS](/packages/max-lit-oauth2-vkontakte/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (4)Used By (0)

Vkontakte OAuth2 client provider
================================

[](#vkontakte-oauth2-client-provider)

[![Build Status](https://camo.githubusercontent.com/639b9d13b8aee469f167457219f275815019f85eef21c68cb74b6109e09c6248/68747470733a2f2f7472617669732d63692e6f72672f6a346b2f6f61757468322d766b6f6e74616b74652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/j4k/oauth2-vkontakte)[![Latest Stable Version](https://camo.githubusercontent.com/1e880d93e29dfc79acbf8eb2a702e63cf1d4e24717814ba4ef779253ff9b995a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a346b2f6f61757468322d766b6f6e74616b74652e737667)](https://packagist.org/packages/j4k/oauth2-vkontakte)[![License](https://camo.githubusercontent.com/5f509454f0f1cd69705d1173abbe718ba3025220dc3262b4718d8d4c1296f004/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6a346b2f6f61757468322d766b6f6e74616b74652e737667)](https://packagist.org/packages/j4k/oauth2-vkontakte)

This package provides [Vkontakte](https://vk.com) integration for [OAuth2 Client](https://github.com/thephpleague/oauth2-client) by the League.

Installation
------------

[](#installation)

```
composer require max-lit/oauth2-vkontakte
```

Configuration
-------------

[](#configuration)

```
$provider = new J4k\OAuth2\Client\Provider\Vkontakte([
    'clientId'     => '1234567',
    'clientSecret' => 's0meRe4lLySEcRetC0De',
    'redirectUri'  => 'https://example.org/oauth-endpoint',
    'scopes'       => ['email', 'offline', 'friends'],
]);
```

Authorization
-------------

[](#authorization)

```
// Authorize if needed
if (PHP_SESSION_NONE === session_status()) session_start();
$isSessionActive = PHP_SESSION_ACTIVE === session_status();
$code            = !empty($_GET['code'])  ? $_GET['code']  : null;
$state           = !empty($_GET['state']) ? $_GET['state'] : null;
$sessionState    = 'oauth2state';

// No code – get some
if (!$code) {
    $authUrl = $provider->getAuthorizationUrl();
    if ($isSessionActive) $_SESSION[$sessionState] = $provider->getState();
    // Redirect user to VK
    header("Location: $authUrl");
    die();
}

// Anti-CSRF
elseif ($isSessionActive && (empty($state) || ($state !== $_SESSION[$sessionState]))) {
    unset($_SESSION[$sessionState]);
    throw new \RuntimeException('Invalid state');
}

// Exchange code to access_token
else {
    try {
        $providerAccessToken = $provider->getAccessToken('authorization_code', ['code' => $code]);
        // Yay, got it!
        var_dump([
            'access_token'  => $providerAccessToken->getToken(),
            'expires'       => $providerAccessToken->getExpires(),
            'user_id'       => $providerAccessToken->getValues()['user_id'],
            'email'         => $providerAccessToken->getValues()['email'], // Only for "email" scope
        ]);
    }
    catch (IdentityProviderException $e) {
        // Log error
        error_log($e->getMessage());
    }
}
```

Helper methods
--------------

[](#helper-methods)

### Public

[](#public)

```
$provider->usersGet([1234, 56789]); // => \J4k\OAuth2\Client\Provider\User[]
$provider->friendsGet(23456);        // => \J4k\OAuth2\Client\Provider\User[]
```

### With additional data

[](#with-additional-data)

```
$providerAccessToken = new \League\OAuth2\Client\Token\AccessToken(['access_token' => 'iAmAccessTokenString']);
$provider->usersGet([1234, 56789], $providerAccessToken); // => \J4k\OAuth2\Client\Provider\User[]
$provider->friendsGet(23456, $providerAccessToken);        // => \J4k\OAuth2\Client\Provider\User[]
```

Contributions
-------------

[](#contributions)

Contributions are very welcome. Please submit a PR

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 53.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~267 days

Total

3

Last Release

3528d ago

PHP version history (2 changes)v1.0.3PHP ~5.4

v1.1.0PHP &gt;=5.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/a1294681c7d936f1d61a4dfaf844ba690e133388097b996ffe6ecc3ac80d7a45?d=identicon)[MaximLit](/maintainers/MaximLit)

---

Top Contributors

[![tinpansoul](https://avatars.githubusercontent.com/u/5672868?v=4)](https://github.com/tinpansoul "tinpansoul (22 commits)")[![j4k](https://avatars.githubusercontent.com/u/4141007?v=4)](https://github.com/j4k "j4k (8 commits)")[![kudmni](https://avatars.githubusercontent.com/u/6409099?v=4)](https://github.com/kudmni "kudmni (5 commits)")[![rakeev](https://avatars.githubusercontent.com/u/1861570?v=4)](https://github.com/rakeev "rakeev (2 commits)")[![xdrew](https://avatars.githubusercontent.com/u/1220667?v=4)](https://github.com/xdrew "xdrew (1 commits)")[![autowp](https://avatars.githubusercontent.com/u/2299280?v=4)](https://github.com/autowp "autowp (1 commits)")[![Pchol](https://avatars.githubusercontent.com/u/1392398?v=4)](https://github.com/Pchol "Pchol (1 commits)")[![artad](https://avatars.githubusercontent.com/u/1460351?v=4)](https://github.com/artad "artad (1 commits)")

---

Tags

packageleague

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/max-lit-oauth2-vkontakte/health.svg)

```
[![Health](https://phpackages.com/badges/max-lit-oauth2-vkontakte/health.svg)](https://phpackages.com/packages/max-lit-oauth2-vkontakte)
```

###  Alternatives

[lab404/laravel-impersonate

Laravel Impersonate is a plugin that allows to you to authenticate as your users.

2.3k16.4M48](/packages/lab404-laravel-impersonate)[vertisan/oauth2-twitch-helix

Twitch (new version Helix) OAuth 2.0 Client Provider for The PHP League OAuth2-Client

1367.4k3](/packages/vertisan-oauth2-twitch-helix)[j4k/oauth2-vkontakte

Vkontakte provider for league/oauth2-client

1252.8k1](/packages/j4k-oauth2-vkontakte)[fof/passport

The OAuth2 (and Laravel passport) compatible oauth extension

3013.3k](/packages/fof-passport)[rickycezar/laravel-jwt-impersonate

Laravel Impersonate is a plugin that allows to you to authenticate as your users.

24117.6k](/packages/rickycezar-laravel-jwt-impersonate)[bulutfon/php-sdk

Bulutfon sdk for Bulutfon-Api

101.4k](/packages/bulutfon-php-sdk)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
