Integrating LINE Login with your web app.
This package requires PHP >=5.4
Install via composer - edit your composer.json
to require the package.
{
"require": {
"kaleidpixel/line-oauth": "0.*"
}
}
Then run composer update
in your terminal to pull it in.
Or use composer require kaleidpixel/line-oauth
<?php
require_once dirname(dirname(__FILE__)) . '/vendor/autoload.php';
use 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)}");
<?php
require_once dirname(dirname(__FILE__)) . '/vendor/autoload.php';
use 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);