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

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

yasinovsky/oauth2-vkontakte
===========================

VKontakte OAuth 2.1 Client Provider for The PHP League OAuth2 Client

3.0.3(2mo ago)261MITPHPPHP ^7.3 || ^8.0

Since Feb 15Pushed 2mo ago1 watchersCompare

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

READMEChangelog (4)Dependencies (6)Versions (6)Used By (0)

VKontakte OAuth 2.1 Client Provider for The PHP League OAuth2 Client
====================================================================

[](#vkontakte-oauth-21-client-provider-for-the-php-league-oauth2-client)

[![Source Code](https://camo.githubusercontent.com/562ed7712840e809423f6d5b72b7e8b135fda04778f49a07b2c4bde72e36415b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f736f757263652d796173696e6f76736b792f6f61757468322d2d766b6f6e74616b74652d626c75652e7376673f7374796c653d666c61742d737175617265)](https://github.com/yasinovsky/oauth2-vkontakte)[![Latest Version](https://camo.githubusercontent.com/c8db51b4a20611a55e55f67798602705e113c3e9f5811379eaa84e8341a4043d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f796173696e6f76736b792f6f61757468322d766b6f6e74616b74652e7376673f7374796c653d666c61742d737175617265)](https://github.com/yasinovsky/oauth2-vkontakte/releases)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://github.com/yasinovsky/oauth2-vkontakte/blob/master/LICENSE.md)[![Total Downloads](https://camo.githubusercontent.com/f8a4f46d58c37f33ca3ed732301e997d015ed854d80874c6a5ebc5500ab491c4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f796173696e6f76736b792f6f61757468322d766b6f6e74616b74652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/yasinovsky/oauth2-vkontakte)

This package provides [VKontakte OAuth 2.1](https://vk.com) support for the PHP League's [OAuth 2.0 Client](https://github.com/thephpleague/oauth2-client).

This package is compliant with [PSR-1](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md), [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md), [PSR-4](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md), and [PSR-7](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-7-http-message.md). If you notice compliance oversights, please send a patch via pull request.

Requirements
------------

[](#requirements)

We support the following versions of PHP:

- PHP 8.5
- PHP 8.4
- PHP 8.3
- PHP 8.2
- PHP 8.1
- PHP 8.0
- PHP 7.4
- PHP 7.3

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

[](#installation)

```
composer require yasinovsky/oauth2-vkontakte
```

Usage
-----

[](#usage)

Create VK application using this [link](https://id.vk.com/about/business/go)

### Configuration

[](#configuration)

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

### Authorization Code Flow

[](#authorization-code-flow)

```
// A session is required to store some session data for later usage
session_start();

// If we don't have an authorization code then get one
if (!isset($_GET['code'])) {

    // Fetch the authorization URL from the provider; this returns the
    // urlAuthorize option and generates and applies any necessary parameters
    // (e.g. state).
    $authorizationUrl = $provider->getAuthorizationUrl();

    // Get the state generated for you and store it to the session.
    $_SESSION['oauth2state'] = $provider->getState();

    // Redirect the user to the authorization URL.
    header('Location: ' . $authorizationUrl);
    exit;

// Check given state against previously stored one to mitigate CSRF attack
} elseif (empty($_GET['state']) || empty($_SESSION['oauth2state']) || $_GET['state'] !== $_SESSION['oauth2state']) {

    if (isset($_SESSION['oauth2state'])) {
        unset($_SESSION['oauth2state']);
    }

    exit('Invalid state');

} else {

    try {

        // Try to get an access token using the authorization code grant.
        $tokens = $provider->getAccessToken('authorization_code', [
            'code' => $_GET['code']
        ]);

        // We have an access token, which we may use in authenticated
        // requests against the service provider's API.
        echo 'Access Token: ' . $tokens->getToken() . "";
        echo 'Refresh Token: ' . $tokens->getRefreshToken() . "";
        echo 'Expired in: ' . $tokens->getExpires() . "";
        echo 'Already expired? ' . ($tokens->hasExpired() ? 'expired' : 'not expired') . "";

        // Using the access token, we may look up details about the
        // resource owner.
        $resourceOwner = $provider->getResourceOwner($tokens);

        var_export($resourceOwner->toArray());

    } catch (\League\OAuth2\Client\Provider\Exception\IdentityProviderException $e) {

        // Failed to get the access token or user details.
        exit($e->getMessage());

    }

}
```

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

[](#helper-methods)

### Public

[](#public)

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

Credits
-------

[](#credits)

- [Victor Yasinovsky](https://github.com/yasinovsky)
- [Yury Arlou](https://github.com/zablik)
- [Jack Wall](https://github.com/j4k)

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance88

Actively maintained with recent releases

Popularity15

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

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

Total

4

Last Release

61d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1bb7c92e2fc5496a0471fcb4a31d52ee3bdbb05aba1c30c02a6bdf6fa230b68d?d=identicon)[yasinovsky](/maintainers/yasinovsky)

---

Top Contributors

[![yasinovsky](https://avatars.githubusercontent.com/u/3243114?v=4)](https://github.com/yasinovsky "yasinovsky (29 commits)")[![tinpansoul](https://avatars.githubusercontent.com/u/5672868?v=4)](https://github.com/tinpansoul "tinpansoul (22 commits)")[![zablik](https://avatars.githubusercontent.com/u/6074433?v=4)](https://github.com/zablik "zablik (7 commits)")[![j4k](https://avatars.githubusercontent.com/u/4141007?v=4)](https://github.com/j4k "j4k (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)")[![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)")[![artad](https://avatars.githubusercontent.com/u/1460351?v=4)](https://github.com/artad "artad (1 commits)")

---

Tags

authenticationauthorisationauthorizationleague-clientleague-oauth2oauthoauth2oauth2-clientvkvk-apivk-idvk-id-sdkvk-oauth2vk-sdkvkontaktevkontakte-apivkontakte-oauth2vkontakte-sdkAuthenticationoauthoauth2authorizationauthorisationoauth2-clientvkvkontakteVK apivkontakte-apivk-sdkleague-clientleague-oauth2vkontakte-oauth2vkontakte-sdkvk-idvk-id-sdkvk-oauth2

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[league/oauth2-server

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.

6.6k136.0M248](/packages/league-oauth2-server)[league/oauth2-google

Google OAuth 2.0 Client Provider for The PHP League OAuth2-Client

42121.2M118](/packages/league-oauth2-google)[stevenmaguire/oauth2-keycloak

Keycloak OAuth 2.0 Client Provider for The PHP League OAuth2-Client

2275.9M27](/packages/stevenmaguire-oauth2-keycloak)[patrickbussmann/oauth2-apple

Sign in with Apple OAuth 2.0 Client Provider for The PHP League OAuth2-Client

1132.5M6](/packages/patrickbussmann-oauth2-apple)[and/oauth

Simple and amazing OAuth library with many providers. Just try it out!

4645.2k2](/packages/and-oauth)[chervand/yii2-oauth2-server

OAuth 2.0 server for Yii 2.0 with MAC tokens support.

1524.2k1](/packages/chervand-yii2-oauth2-server)

PHPackages © 2026

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