PHP code example of kaleidpixel / line-oauth

1. Go to this page and download the library: Download kaleidpixel/line-oauth library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kaleidpixel / line-oauth example snippets



KaleidPixel\OAuth\LineOAuth;

$connection = new LineOAuth(API_KEY_LINE, API_SECRET_LINE);
$_SESSION['user']['oauth_token'] = $connection->state;
$_SESSION['user']['oauth_provider'] = 'line';

header("Location: {$connection->oauthUrl(OAUTH_CALLBACK_URL)}");


KaleidPixel\OAuth\LineOAuth;

if (isset($_REQUEST['code']) && $_REQUEST['state'] === $_SESSION['user']['oauth_token']) {
    $connection = new LineOAuth(API_KEY_LINE, API_SECRET_LINE, $_SESSION['user']['oauth_token']);
    $token = $connection->getToken($_REQUEST['code'], OAUTH_CALLBACK_URL);

    if (!is_null($token)) {
        $user = $connection->getUser($token);

        if(!empty($user)) {
            $_SESSION['user']['provider'] = $_SESSION['user']['oauth_provider'];
            $_SESSION['user']['provider_id'] = $user->userId;
            $_SESSION['user']['name'] = $user->displayName;
        }
    }
}

var_dump($_SESSION);