PHPackages                             mihai3332001/oauth2-anaf - 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. mihai3332001/oauth2-anaf

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

mihai3332001/oauth2-anaf
========================

Anaf E-Factura Symfony Plugin

v1.0.0(2y ago)341MITPHPPHP ^8.0

Since Nov 25Pushed 2y ago2 watchersCompare

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

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

oauth2-anaf
===========

[](#oauth2-anaf)

About Anaf E-Factura Symfony Plugin

Basic setup:

```
 // Use:
 $provider = new \League\OAuth2\Client\Provider\GenericProvider([
    'clientId'                => 'XXXXXX',    // The client ID assigned to you by the provider
    'clientSecret'            => 'XXXXXX',    // The client password assigned to you by the provider
    'redirectUri'             => 'https://my.example.com/your-redirect-url/',
    'urlAuthorize'            => 'https://logincert.anaf.ro/anaf-oauth2/v1/authorize',
    'urlAccessToken'          => 'https://logincert.anaf.ro/anaf-oauth2/v1/token',
     'urlResourceOwnerDetails' => 'https://logincert.anaf.ro/anaf-oauth2/v1/revoke'
]);

 // 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();

// Optional, only required when PKCE is enabled.
// Get the PKCE code generated for you and store it to the session.
$_SESSION['oauth2pkceCode'] = $provider->getPkceCode();

// 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 {

    // Optional, only required when PKCE is enabled.
    // Restore the PKCE code stored in the session.
    $provider->setPkceCode($_SESSION['oauth2pkceCode']);

    // Try to get an access token using the authorization code grant.
    $accessToken = $provider->getAccessToken('authorization_code', [
        'code' => $_GET['code']
    ]);
    $refreshToken = $accessToken->getToken();
    // We have an access token, which we may use in authenticated
    // requests against the service provider's API.
    echo 'Access Token: ' . $accessToken->getToken() . "";
    echo 'Refresh Token: ' . $accessToken->getRefreshToken() . "";
    echo 'Expired in: ' . $accessToken->getExpires() . "";
    echo 'Already expired? ' . ($accessToken->hasExpired() ? 'expired' : 'not expired') . "";

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

    var_export($resourceOwner->toArray());

    // The provider provides a way to get an authenticated API request for
    // the service, using the access token; it returns an object conforming
    // to Psr\Http\Message\RequestInterface.
    $request = $provider->getAuthenticatedRequest(
        'GET',
        'https://service.example.com/resource',
        $accessToken
    );

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

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

}

}

```

Upload XML E-factura - POST method

```
     $provider =  new Anaf([
                'clientId'                => 'XXXXXX',    // The client ID assigned to you by the provider
                'clientSecret'            => 'XXXXXX',    // The client password assigned to you by the provider
                'redirectUri'             => 'https://my.example.com/your-redirect-url/',
                'urlAuthorize'            => 'https://logincert.anaf.ro/anaf-oauth2/v1/authorize',
                'urlAccessToken'          => 'https://logincert.anaf.ro/anaf-oauth2/v1/token',
                'urlResourceOwnerDetails' => 'https://logincert.anaf.ro/anaf-oauth2/v1/revoke'
            ]);

        //document that you want to send to ANAF;
        $options['body'] = $document;
        //cif code of your company
        // $getAnafRefreshToken your anaf token
        $requestAnafPOST = $provider->getAuthenticatedRequest(
                    'POST',
                    'https://api.anaf.ro/test/FCTEL/rest/upload?standard=UBL&cif=XXX',
                    $getAnafRefreshToken(),
                    $options
                );
        //your parse response, you can also use getResponse for status code
        $response = $provider->getParsedResponse($requestAnafPOST);

        $crawler = new Crawler($response);
        $indexIncarcare = $crawler->filterXPath('header')->attr('index_incarcare');

```

Stare Mesaj E-factura - GET method

```
       $provider =  new Anaf([
                'clientId'                => 'XXXXXX',    // The client ID assigned to you by the provider
                'clientSecret'            => 'XXXXXX',    // The client password assigned to you by the provider
                'redirectUri'             => 'https://my.example.com/your-redirect-url/',
                'urlAuthorize'            => 'https://logincert.anaf.ro/anaf-oauth2/v1/authorize',
                'urlAccessToken'          => 'https://logincert.anaf.ro/anaf-oauth2/v1/token',
                'urlResourceOwnerDetails' => 'https://logincert.anaf.ro/anaf-oauth2/v1/revoke'
            ]);

            $idincarcareSPV = 'XXXXXX';

            $requestAnafGET = $provider->getAuthenticatedRequest(
                'GET',
                'https://api.anaf.ro/test/FCTEL/rest/stareMesaj?id_incarcare=' . $idIncarcareSPV,
                $getAnafRefreshToken(),
            );

            $responseGET = $provider->getParsedResponse($requestAnafGET);
            $crawler2 = new Crawler($responseGET);
            $stareIncarcare = $crawler2->filterXPath('header')->attr('stare');
            $idDescarcare = $crawler2->filterXPath('header')->attr('id_descarcare');

```

Descarcare Raspuns E-factura - GET method

```
          $requestAnafDescarcare = $provider->getAuthenticatedRequest(
                'GET',
                'https://api.anaf.ro/test/FCTEL/rest/descarcare?id=' .$idDescarcare,
                $getAnafRefreshToken(),
           );
           $requestAnafDescarcareDOC = $provider->getParsedResponse($requestAnafDescarcare);

```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity47

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

Unknown

Total

1

Last Release

899d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/68321da4d3858f6f54e0786d4dc273ba4d88b4c64d95606e8a99946a83e9bb54?d=identicon)[mihai3332001](/maintainers/mihai3332001)

---

Top Contributors

[![mihai3332001](https://avatars.githubusercontent.com/u/34579013?v=4)](https://github.com/mihai3332001 "mihai3332001 (3 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mihai3332001-oauth2-anaf/health.svg)

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

###  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)
