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

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

himanshu-dixit/oauth2-vkontakte
===============================

Vkontakte provider for league/oauth2-client

06PHP

Since Aug 14Pushed 8y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)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 j4k/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

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/5d8ff90568dac14dc2fd3c57df7ecf9ac8a4bfa2a5d1a1958c0c38fca616be50?d=identicon)[hudixt](/maintainers/hudixt)

---

Top Contributors

[![himanshu-dixit](https://avatars.githubusercontent.com/u/6849438?v=4)](https://github.com/himanshu-dixit "himanshu-dixit (1 commits)")

### Embed Badge

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

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

###  Alternatives

[namshi/jose

JSON Object Signing and Encryption library for PHP.

1.8k99.6M101](/packages/namshi-jose)[league/oauth1-client

OAuth 1.0 Client Library

99698.8M106](/packages/league-oauth1-client)[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[gesdinet/jwt-refresh-token-bundle

Implements a refresh token system over Json Web Tokens in Symfony

70516.4M35](/packages/gesdinet-jwt-refresh-token-bundle)[league/oauth2-google

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

41721.2M118](/packages/league-oauth2-google)[illuminate/auth

The Illuminate Auth package.

9327.3M1.0k](/packages/illuminate-auth)

PHPackages © 2026

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