Giter Site home page Giter Site logo

oauth2-anaf's Introduction

OAuth 2.0 ANAF

GitHub Workflow Status (main) Total Downloads Latest Version License

ANAF Provider for OAuth 2.0 Client

This package provides ANAF OAuth 2.0 support for the PHP League's OAuth 2.0 Client.


Installation

To install, use composer:

composer require andalisolutions/oauth2-anaf

Usage

Usage is the same as The League's OAuth client, using \Anaf\OAuth2\Client\Provider\AnafProvider as the provider.

Authorization Code Flow

$provider = new Anaf\OAuth2\Client\Provider\AnafProvider(
    clientId: '{anaf-client-id}',
    clientSecret: '{anaf-client-secret}',
    redirectUrl: 'https://example.com/callback-url',
);

// Redirect to the authorization URL
$authorizationUrl = $provider->getAuthorizationUrl();
header('Location: ' . $authorizationUrl);

// This part will be in your callback script
if (isset($_GET['code'])) {
    try {
        $accessToken = $provider->getAccessToken('authorization_code', [
            'code' => $_GET['code'],
        ]);
        // We have an access token, which we may use in authenticated
        // requests against the service provider's API.
        echo 'Access Token: ' . $accessToken->getToken() . "<br>";
        echo 'Refresh Token: ' . $accessToken->getRefreshToken() . "<br>";
        echo 'Expired in: ' . $accessToken->getExpires() . "<br>";
        echo 'Already expired? ' . ($accessToken->hasExpired() ? 'expired' : 'not expired') . "<br>";

    } catch (Exception $e) {
        // Handle errors, such as an invalid code
    }
}

Testing

composer test

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.

oauth2-anaf's People

Contributors

ciungulete avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

oauth2-anaf's Issues

eroare la redirect

Salut,
Dupa ce se face auth cu token, se face redirect catre CallBack si apare eroare in browser: "The page isn’t redirecting properly".
in callback vine: domain.ro/?code=a6712d84faa190a1bf1664a5=&state=642734cce2

exista o librarie de erori in care pot verifica?

Os: macOs, browser: firefox (versiunea 90.0)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.