PHPackages                             rudra/oauth-client - 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. rudra/oauth-client

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

rudra/oauth-client
==================

oauth client

v26.7.27(1mo ago)03191MPL-2.0PHPPHP ^8.3

Since Jun 27Pushed 2w ago2 watchersCompare

[ Source](https://github.com/Jagepard/Rudra-OAuthClient)[ Packagist](https://packagist.org/packages/rudra/oauth-client)[ RSS](/packages/rudra-oauth-client/feed)WikiDiscussions master Synced yesterday

READMEChangelog (10)Dependencies (4)Versions (12)Used By (1)

[![CodeFactor](https://camo.githubusercontent.com/1b4a890de7309437fc42f183fd1c5d78ef76c9bb95540db33eee040db72bff12/68747470733a2f2f7777772e636f6465666163746f722e696f2f7265706f7369746f72792f6769746875622f6a616765706172642f72756472612d6f61757468636c69656e742f6261646765)](https://www.codefactor.io/repository/github/jagepard/rudra-oauthclient)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[](#)

OAuthClient | [API](https://github.com/Jagepard/Rudra-OAuthClient/blob/master/docs.md "Documentation API")
==========================================================================================================

[](#oauthclient--api)

A lightweight, extensible OAuth 2.0 client for the [Rudra Framework](https://github.com/Jagepard/Rudra). Follows the KISS principle: no unnecessary abstractions, no hidden magic — just a straightforward way to integrate social login.

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

[](#requirements)

- PHP 8.3+ (uses `#[\Override]` attribute and typed properties)
- cURL extension enabled

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

[](#installation)

```
composer require rudra/oauth-client
```

Configuration
-------------

[](#configuration)

In your Rudra application settings file (`setting.($env).yml`), define your providers. The top-level key (e.g., `yandex`) is the provider identifier used in callbacks:

```
oauth:
    yandex:
        class: Rudra\OAuthClient\Provider\Yandex
        client_id: "your_client_id"
        client_secret: "your_client_secret"
        redirect_uri: "https://your-site.com/oauth?provider=yandex"
```

You can add as many providers as you need:

```
oauth:
    yandex:
        class: Rudra\OAuthClient\Provider\Yandex
        client_id: "yandex_id"
        client_secret: "yandex_secret"
        redirect_uri: "https://your-site.com/oauth?provider=yandex"
    vk:
        class: Rudra\OAuthClient\Provider\VK
        client_id: "vk_id"
        client_secret: "vk_secret"
        redirect_uri: "https://your-site.com/oauth?provider=vk"
```

> 💡 **Note:** The `redirect_uri` must include the `provider` query parameter matching the config key (e.g., `?provider=yandex`). This is how the callback handler identifies which provider to use.

Integration Example (Rudra Task)
--------------------------------

[](#integration-example-rudra-task)

```
namespace App\Containers\Auth\Task;

use Rudra\Auth\AuthFacade as Auth;
use Rudra\Container\Facades\Rudra;
use Rudra\Container\Facades\Session;
use Rudra\Redirect\RedirectFacade as Redirect;
use App\Containers\DB\Entity\Users;

class OAuth
{
    /**
     * Authorizes and, if necessary, registers a user
     */
    public static function run(array $inputData): void
    {
        if (!isset($inputData['code'], $inputData['provider'])) {
            return;
        }

        $oauthConfig = Rudra::config()->get('oauth');
        $providerKey = $inputData['provider'];

        if (!isset($oauthConfig[$providerKey])) {
            return; // Unknown provider
        }

        $providerConfig = $oauthConfig[$providerKey];
        $providerClass  = $providerConfig['class'];

        $provider = new $providerClass($providerConfig);
        $provider->authenticate($inputData['code']);

        $oauthUser = (object) $provider->user();
        $email     = $oauthUser->default_email ?? $oauthUser->email ?? ($oauthUser->login . '@' . $provider->getName());
        $login     = $oauthUser->login ?? $oauthUser->name;
        $user      = Users::getUser($email);

        if (empty($user)) {
            Users::create([
                'name'     => $login,
                'email'    => strtolower($email),
                'password' => $providerKey,
            ]);
            $user = Users::getUser($email);
        }

        $user = $user[0];
        session_regenerate_id(true);
        Session::set(["token", md5($user['password'] . $user['email'] . Auth::getSessionHash())]);
        Session::set(["user", $user]);
        Redirect::run("admin/item");
    }
}
```

Creating a Custom Provider
--------------------------

[](#creating-a-custom-provider)

To add a new OAuth provider (e.g., VK, Google, GitHub), extend `AbstractProvider` and implement the `authenticate()` method.

**Important:** The `request()` method has dual behavior:

- `request($params)` — sends a **POST** request to the `access_token` URL.
- `request()` (without parameters) — sends a **GET** request to the `remote_api` URL.

```
namespace Rudra\OAuthClient\Provider;

class CustomProvider extends AbstractProvider
{
    public function __construct(array $config)
    {
        parent::__construct($config);

        $this->name = 'custom';
        $this->urls = [
            'auth'         => 'https://provider.com/oauth/authorize',
            'access_token' => 'https://provider.com/oauth/token',
            'remote_api'   => 'https://provider.com/api/userinfo',
        ];
    }

    #[\Override]
    public function authenticate(?string $code = null): void
    {
        if (!$code) {
            return;
        }

        // 1. Exchange code for token (POST)
        $token = $this->request([
            'grant_type' => 'authorization_code',
            'code'       => $code,
        ]);

        if (!isset($token['access_token'])) {
            return;
        }

        // 2. Fetch user data (GET)
        $this->urls['remote_api'] .= '?access_token=' . $token['access_token'];
        $this->user = $this->request();
    }
}
```

License
-------

[](#license)

This project is licensed under the **Mozilla Public License 2.0 (MPL-2.0)** — a free, open-source license that:

- Requires preservation of copyright and license notices,
- Allows commercial and non-commercial use,
- Requires that any modifications to the original files remain open under MPL-2.0,
- Permits combining with proprietary code in larger works.

📄 Full license text: [LICENSE](./LICENSE)
🌐 Official MPL-2.0 page:

###  Health Score

48

—

FairBetter than 94% of packages

Maintenance94

Actively maintained with recent releases

Popularity15

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 98.3% 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 ~37 days

Recently: every ~0 days

Total

11

Last Release

44d ago

Major Versions

v25.6 → v26.12025-12-29

PHP version history (2 changes)v25.10PHP &gt;=8.3

v26.7PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/75e65761bdd94035d1c783773a706d5722ce3164fe55d9722581c2cb4a642d8c?d=identicon)[jagepard](/maintainers/jagepard)

---

Top Contributors

[![Jagepard](https://avatars.githubusercontent.com/u/4591345?v=4)](https://github.com/Jagepard "Jagepard (57 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (1 commits)")

---

Tags

oauthoauth-clientrudra

### Embed Badge

![Health badge](/badges/rudra-oauth-client/health.svg)

```
[![Health](https://phpackages.com/badges/rudra-oauth-client/health.svg)](https://phpackages.com/packages/rudra-oauth-client)
```

###  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.7k151.3M327](/packages/league-oauth2-server)[league/oauth2-client

OAuth 2.0 Client Library

3.8k132.3M1.4k](/packages/league-oauth2-client)[league/oauth1-client

OAuth 1.0 Client Library

995114.9M127](/packages/league-oauth1-client)[knpuniversity/oauth2-client-bundle

Integration with league/oauth2-client to provide services

84218.9M90](/packages/knpuniversity-oauth2-client-bundle)[socialiteproviders/manager

Easily add new or override built-in providers in Laravel Socialite.

42649.8M606](/packages/socialiteproviders-manager)[league/oauth2-google

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

42524.2M199](/packages/league-oauth2-google)

PHPackages © 2026

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