PHPackages                             galichvitaliy/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. galichvitaliy/oauth2-vkontakte

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

galichvitaliy/oauth2-vkontakte
==============================

Vkontakte provider for league/oauth2-client

v2.0.2(4y ago)0285MITPHPPHP ^7.3 || ^8.0

Since Mar 28Pushed 4y agoCompare

[ Source](https://github.com/galichvitaliy/oauth2-vkontakte)[ Packagist](https://packagist.org/packages/galichvitaliy/oauth2-vkontakte)[ RSS](/packages/galichvitaliy-oauth2-vkontakte/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (1)Dependencies (3)Versions (11)Used By (0)

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

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

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

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

[](#installation)

```
composer require galichvitaliy/oauth2-vkontakte
```

Versions
--------

[](#versions)

Use `v2.0+` for `"php": "^7.3 || ^8.0"`

Use `v1.2.3` for `"php": "^5.6 || ^7.0"`

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\VkontakteUser[]
$provider->friendsGet(23456);        // => \J4k\OAuth2\Client\Provider\VkontakteUser[]
```

### 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\VkontakteUser[]
$provider->friendsGet(23456, $providerAccessToken);        // => \J4k\OAuth2\Client\Provider\VkontakteUser[]
```

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

[](#contributions)

Contributions are very welcome. Please submit a PR

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~263 days

Recently: every ~324 days

Total

10

Last Release

1737d ago

Major Versions

v1.2.3 → v2.0.02021-02-20

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

v1.1.0PHP &gt;=5.5

1.0.0PHP &gt;=5.6

v1.2.1PHP ^5.6 || ^7.0

v2.0.0PHP ^7.1 || ^8.0

v2.0.1PHP ^7.3 || ^8.0

### Community

Maintainers

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

---

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 (7 commits)")[![zablik](https://avatars.githubusercontent.com/u/6074433?v=4)](https://github.com/zablik "zablik (5 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)")[![galichvitaliy](https://avatars.githubusercontent.com/u/2140418?v=4)](https://github.com/galichvitaliy "galichvitaliy (2 commits)")[![autowp](https://avatars.githubusercontent.com/u/2299280?v=4)](https://github.com/autowp "autowp (1 commits)")[![Alexander1000](https://avatars.githubusercontent.com/u/6797418?v=4)](https://github.com/Alexander1000 "Alexander1000 (1 commits)")[![artad](https://avatars.githubusercontent.com/u/1460351?v=4)](https://github.com/artad "artad (1 commits)")[![xdrew](https://avatars.githubusercontent.com/u/1220667?v=4)](https://github.com/xdrew "xdrew (1 commits)")

---

Tags

packageleague

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[vertisan/oauth2-twitch-helix

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

1176.2k7](/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

3114.1k](/packages/fof-passport)

PHPackages © 2026

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