Simplifying OAuth2.0 authentication Integration in PHP Applications: OAuth 2.0 Client

Source: Internet
Author: User
Tags oauth

Simplifying OAuth2.0 authentication Integration in PHP Applications: OAuth 2.0 Client

Read Catalogue

    • Validation code Flow
    • Refreshing a Token
    • Built-in Providers
This package allows you to integrate OAuth2.0 authentication into your PHP application in a very simple way.
Usage
Verify the code flow?
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 $provider = new League\OAuth2\Client\Provider\<ProviderName>(array(    ‘clientId‘ =>  ‘XXXXXXXX‘,    ‘clientSecret‘=>  ‘XXXXXXXX‘,    ‘redirectUri‘=>  ‘https://your-registered-redirect-uri/‘,    ‘scopes‘ => array(‘email‘, ‘...‘, ‘...‘),));if ( ! isset($_GET[‘code‘])) {    // If we don‘t have an authorization code then get one    header(‘Location: ‘.$provider->getAuthorizationUrl());    exit;} else {    // Try to get an access token (using the authorization code grant)    $token = $provider->getAccessToken(‘authorization_code‘, [        ‘code‘ => $_GET[‘code‘]    ]);    // If you are using Eventbrite you will need to add the grant_type parameter (see below)    $token = $provider->getAccessToken(‘authorization_code‘, [        ‘code‘ => $_GET[‘code‘],        ‘grant_type‘ => ‘authorization_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 user‘s details        $userDetails = $provider->getUserDetails($token);        // Use these details to create a new profile        printf(‘Hello %s!‘, $userDetails->firstName);    } catch (Exception $e) {        // Failed to get user details        exit(‘Oh dear...‘);    }     // 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;}
Back to top refreshing a Token?
12345678 $provider = new League\OAuth2\Client\Provider\<ProviderName>(array(    ‘clientId‘ =>  ‘XXXXXXXX‘,    ‘clientSecret‘=>  ‘XXXXXXXX‘,    ‘redirectUri‘=>  ‘https://your-registered-redirect-uri/‘));$grant = new \League\OAuth2\Client\Grant\RefreshToken();$token = $provider->getAccessToken($grant, [‘refresh_token‘ => $refreshToken]);
Back to the top of built-in Providers

This package is now built with support:

    • Eventbrite
    • Facebook
    • Github
    • Google
    • Instagram
    • Linkedin
    • Microsoft

Project home:http://www.open-open.com/lib/view/home/1417502997514

Simplifying OAuth2.0 authentication Integration in PHP Applications: OAuth 2.0 Client

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.