PHPackages                             autowp/oauth2-vk - 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. autowp/oauth2-vk

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

autowp/oauth2-vk
================

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

1.0.2(9y ago)1657↓100%MITPHPPHP &gt;=5.3.0

Since Jan 16Pushed 9y ago1 watchersCompare

[ Source](https://github.com/autowp/oauth2-vk)[ Packagist](https://packagist.org/packages/autowp/oauth2-vk)[ RSS](/packages/autowp-oauth2-vk/feed)WikiDiscussions master Synced today

READMEChangelog (3)Dependencies (2)Versions (3)Used By (0)

[![Build Status](https://camo.githubusercontent.com/a320a5679296f5abe5f1f446e0a534eb40a716ce392a02570e4e86163191a470/68747470733a2f2f7472617669732d63692e6f72672f6175746f77702f6f61757468322d766b2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/autowp/oauth2-vk)[![Code Climate](https://camo.githubusercontent.com/7f18664121a2de5a08d2893b538681c50d0e1b6c49996ed822097b4ae45f886f/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6175746f77702f6f61757468322d766b2f6261646765732f6770612e737667)](https://codeclimate.com/github/autowp/oauth2-vk)

VK Provider for OAuth 2.0 Client
================================

[](#vk-provider-for-oauth-20-client)

This package provides VK OAuth 2.0 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) and [PSR-4](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md). If you notice compliance oversights, please send a patch via pull request.

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

[](#requirements)

The following versions of PHP are supported.

- PHP 5.5
- PHP 5.6
- PHP 7.0
- HHVM

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

[](#installation)

To install, use composer:

```
composer require autowp/oauth2-vk

```

Usage
-----

[](#usage)

### Authorization Code Flow

[](#authorization-code-flow)

```
$provider = new Autowp\OAuth2\Client\Provider\Vk([
    'clientId'      => '{vk-app-id}',
    'clientSecret'  => '{vk-app-secret}',
    'redirectUri'   => 'https://example.com/callback-url',
    'display'       => 'page',
    'response_type' => 'code'
]);

if (!empty($_GET['error'])) {

    // Got an error, probably user denied access
    exit('Got error: ' . $_GET['error']);

} elseif (empty($_GET['code'])) {

    // If we don't have an authorization code then get one
    $authUrl = $provider->getAuthorizationUrl();
    $_SESSION['oauth2state'] = $provider->getState();
    header('Location: ' . $authUrl);
    exit;

} elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) {

    // State is invalid, possible CSRF attack in progress
    unset($_SESSION['oauth2state']);
    exit('Invalid state');

} else {

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

    // Optional: Now you have a token you can look up a users profile data
    try {

        // We got an access token, let's now get the owner details
        $ownerDetails = $provider->getResourceOwner($token);

        // Use these details to create a new profile
        printf('Hello %s!', $ownerDetails->getFirstName());

    } catch (Exception $e) {

        // Failed to get user details
        exit('Something went wrong: ' . $e->getMessage());

    }

    // Use this to interact with an API on the users behalf
    echo $token->accessToken;

    // Use this to get a new access token if the old one expires
    echo $token->refreshToken;

    // Number of seconds until the access token will expire, and need refreshing
    echo $token->expires;
}
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](https://github.com/autowp/oauth2-vl/blob/master/LICENSE.md) for more information.

###  Health Score

28

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

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.

###  Release Activity

Cadence

Every ~79 days

Total

3

Last Release

3560d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4999be04a27b664b60ee543d6b89adfda8bd8927a72f7818b7d33758db7947b8?d=identicon)[autowp](/maintainers/autowp)

---

Top Contributors

[![autowp](https://avatars.githubusercontent.com/u/2299280?v=4)](https://github.com/autowp "autowp (13 commits)")

---

Tags

clientAuthenticationoauthoauth2authorizationvk

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/autowp-oauth2-vk/health.svg)

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

###  Alternatives

[cakedc/oauth2-cognito

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

18588.1k](/packages/cakedc-oauth2-cognito)

PHPackages © 2026

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