PHPackages                             startsevdenis/oauth2-mosru - 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. startsevdenis/oauth2-mosru

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

startsevdenis/oauth2-mosru
==========================

Mos.ru provider for league/oauth2-client

0.3.6(2mo ago)02.0kMITPHPPHP &gt;=7.2

Since Jun 2Pushed 2mo ago1 watchersCompare

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

READMEChangelog (5)Dependencies (3)Versions (6)Used By (0)

Mos.ru OAuth2 client provider
=============================

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

[![Latest Version](https://camo.githubusercontent.com/c64ad031991b3626cc98a89f23ded49fa86d954251e9381bdd1cc08dd9e11c64/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6165676f2f6f61757468322d6d61696c72752e737667)](https://packagist.org/packages/aego/oauth2-mailru)[![License](https://camo.githubusercontent.com/2f9c088f21aa6dfae74a3d0f0ba1e3ae2b54d9e745455e4c76007dd3cbc5bce8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6165676f2f6f61757468322d6d61696c72752e737667)](https://packagist.org/packages/aego/oauth2-mailru)

Данный пакет предоставляет интеграцию [Mos.ru](https://login.mos.ru) для [OAuth2 Client](https://github.com/thephpleague/oauth2-client).

Установка
---------

[](#установка)

```
composer require knpuniversity/oauth2-client-bundle
composer require startsevdenis/oauth2-mosru
```

Использоваие
------------

[](#использоваие)

### 1. Настройка клиента

[](#1-настройка-клиента)

```
#knpu_oauth2_client.yaml

knpu_oauth2_client:
  clients:
    mosru:
      type: generic
      provider_class: StartsevDenis\OAuth2\Client\Provider\MosruProvider
      provider_options:
        environment: '%env(MOSRU_APP_ENV)%' #production or test
        scope: [ 'openid', 'profile', 'contacts', 'usr_grps' ] #необязательный параметр scope по умолчанию 'openid', 'profile', 'contacts'
      client_id: '%env(MOSRU_APP_ID)%'
      client_secret: '%env(MOSRU_APP_SECRET)%'
      redirect_route: mosru_check
```

### 2. Два роута в контроллере

[](#2-два-роута-в-контроллере)

```
# AuthConroller

use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;

class AuthController extends AbstractController
{
...
    /**
     * Auth start
     *
     * @Route("/connect/mosru", name="connect_mosru_start")
     */
    public function connectAction(ClientRegistry $clientRegistry)
    {
        return $clientRegistry
            ->getClient('mosru')
            ->redirect();
    }

    /**
     * Auth end
     * @Route("/auth/mosru/check", name="mosru_check")
     */
    public function mosruCheck()
    {
        #logic
    }
}
```

### 3. Авторизатор

[](#3-авторизатор)

В зависимости от версии symfony используем соответствующий авторизатор. Примеры авторизаторв на странице [KnpUOAuth2ClientBundle](https://github.com/knpuniversity/oauth2-client-bundle#authenticating-with-the-new-symfony-authenticator)

Пример авторизатора Symfony 5.4

```
#security.yaml

security:
  enable_authenticator_manager: true
  ...
  firewalls:
    ...
    main:
      ...
      custom_authenticators:
        - App\Security\MosRuAuthenticator

```

```
# App\Security\MosRuAuthenticator

namespace App\Security;

use Doctrine\ORM\EntityManagerInterface;
use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
use KnpU\OAuth2ClientBundle\Security\Authenticator\OAuth2Authenticator;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
use Symfony\Component\Security\Http\Authenticator\Passport\SelfValidatingPassport;

class MosRuAuthenticator extends OAuth2Authenticator
{
    private $clientRegistry;
    private $entityManager;
    private $router;

    public function __construct(ClientRegistry $clientRegistry, EntityManagerInterface $entityManager, RouterInterface $router)
    {
        $this->clientRegistry = $clientRegistry;
        $this->entityManager = $entityManager;
        $this->router = $router;
    }

    public function supports(Request $request): ?bool
    {
        return $request->attributes->get('_route') === 'mosru_check';
    }

    public function authenticate(Request $request): Passport
    {
        $client = $this->clientRegistry->getClient('mosru');
        $accessToken = $this->fetchAccessToken($client);
        return new SelfValidatingPassport(
            new UserBadge($accessToken->getToken(), function() use ($accessToken, $client) {
                /* @var \StartsevDenis\OAuth2\Client\Provider\MosruResourceOwner */
                $owner = $client->fetchUserFromToken($accessToken);

                #getUser logic

                return $user;
            })
        );
    }

    public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response
    {
        //return url logic

        $targetUrl = $this->router->generate('index_page');

        return new RedirectResponse($targetUrl);

        // or, on success, let the request continue to be handled by the controller
        //return null;
    }

    public function onAuthenticationFailure(Request $request, AuthenticationException $exception): ?Response
    {
        $message = strtr($exception->getMessageKey(), $exception->getMessageData());

        return new Response($message, Response::HTTP_FORBIDDEN);
    }
}
```

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance85

Actively maintained with recent releases

Popularity19

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

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

Total

5

Last Release

75d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1306b4fc18d8a624bf4cc3d4ee8093836b9915fbb71e8964f6dac357ad54ea71?d=identicon)[startsevdenis](/maintainers/startsevdenis)

---

Top Contributors

[![startsevdenis](https://avatars.githubusercontent.com/u/621283?v=4)](https://github.com/startsevdenis "startsevdenis (9 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/startsevdenis-oauth2-mosru/health.svg)

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

###  Alternatives

[league/oauth2-google

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

41721.2M118](/packages/league-oauth2-google)[knpuniversity/oauth2-client-bundle

Integration with league/oauth2-client to provide services

83416.7M61](/packages/knpuniversity-oauth2-client-bundle)[thenetworg/oauth2-azure

Azure Active Directory OAuth 2.0 Client Provider for The PHP League OAuth2-Client

2509.6M48](/packages/thenetworg-oauth2-azure)[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)[microsoft/kiota-authentication-phpleague

Authentication provider for Kiota using the PHP League OAuth 2.0 client to authenticate against the Microsoft Identity platform

153.2M7](/packages/microsoft-kiota-authentication-phpleague)

PHPackages © 2026

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