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

ActiveLibrary

zablik/oauth2-vkontakte
=======================

Vkontakte provider for league/oauth2-client

v2.0.2(4y ago)6225.5k—0%8MITPHPPHP ^7.3 || ^8.0

Since Mar 28Pushed 4y ago2 watchersCompare

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

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

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

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

[![Build Status](https://camo.githubusercontent.com/25452973cd904eb046e4f10d60e1b80bd4b1a1e37e8ad6dba25279b0c76185f4/68747470733a2f2f7472617669732d63692e636f6d2f7a61626c696b2f6f61757468322d766b6f6e74616b74652e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/zablik/oauth2-vkontakte)[![Latest Stable Version](https://camo.githubusercontent.com/4acc3bd2af5bbeba2d1c180659359f607417c3f88fe32f64594f7630add6e8cf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7a61626c696b2f6f61757468322d766b6f6e74616b74652e737667)](https://packagist.org/packages/zablik/oauth2-vkontakte)[![License](https://camo.githubusercontent.com/b0661e68336cb52e0610238e83c3a9c966c98225ed748658b66dcbb2912b8272/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7a61626c696b2f6f61757468322d766b6f6e74616b74652e737667)](https://packagist.org/packages/zablik/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 zablik/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

42

—

FairBetter than 90% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity40

Moderate usage in the ecosystem

Community19

Small or concentrated contributor base

Maturity75

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

Recently: every ~333 days

Total

10

Last Release

1657d 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/17b7e6a297bfa32cf8b83b0af30c15a02dc5ff001e58890edba06733c342d7cd?d=identicon)[zablik](/maintainers/zablik)

---

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 (7 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)")[![Alexander1000](https://avatars.githubusercontent.com/u/6797418?v=4)](https://github.com/Alexander1000 "Alexander1000 (1 commits)")[![autowp](https://avatars.githubusercontent.com/u/2299280?v=4)](https://github.com/autowp "autowp (1 commits)")[![xdrew](https://avatars.githubusercontent.com/u/1220667?v=4)](https://github.com/xdrew "xdrew (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/zablik-oauth2-vkontakte/health.svg)

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

###  Alternatives

[league/plates

Plates, the native PHP template system that's fast, easy to use and easy to extend.

1.5k5.9M232](/packages/league-plates)[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)

PHPackages © 2026

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