wilkques / line-login-sdk-php
LINE Login SDK for PHP
v5.1.1
2023-07-25 07:50 UTC
Requires
- php: >=7.0
- ext-curl: *
- ext-json: *
- wilkques/http-client: ^4.0.0
- wilkques/php-helper: ^3.0.0
Suggests
- wilkques/pkce-php: Required to use the PKCE with OAuth2.0
README
Installation
composer require wilkques/line-login-sdk-php
Scopes
How to use
-
Authorization
use Wilkques\LINE\LINE; $line = new LINE('<CHANNEL_ID>'); // or $line = LINE::clientId('<CHANNEL_ID>'); $code = $_GET['code'] ?? null; if ($code) { $token = $line->clientSecret('<CHANNEL_SECRET>')->token($code, '<REDIRECT_URI>'); $userProfile = $line->userProfile($token->accessToken()); exit; } $url = $line->generateLoginUrl([ // Callback URL: https://developers.line.biz/console/channel/<channel id>/line-login 'https://yourdomain.com', // Permissions requested from the user: https://developers.line.biz/en/docs/line-login/integrate-line-login/#scopes [ 'profile', 'openid', 'email' ] ]); // or $url = $line->generateLoginUrl([ // Callback URL: https://developers.line.biz/console/channel/<channel id>/line-login 'redirect_uri' => $url, // Permissions requested from the user: https://developers.line.biz/en/docs/line-login/integrate-line-login/#scopes 'scope' => ['openid', 'openid'] ]);
-
PKCE Authorization
- command
composer require wilkques/pkce-php
-
use Wilkques\LINE\LINE; use Wilkques\PKCE\Generator; $line = new LINE('<CHANNEL_ID>'); // or $line = LINE::clientId('<CHANNEL_ID>'); $pkce = Generator::generate(); $code = $_GET['code'] ?? null; if ($code) { $codeVerifier = $_GET['state'] ?? null; $token = $line->clientSecret('<CHANNEL_SECRET>')->token($code, '<REDIRECT_URI>', $codeVerifier); $userProfile = $line->userProfile($token->accessToken()); exit; } $codeVerifier = $pkce->getCodeVerifier(); $codeChallenge = $pkce->getCodeChallenge(); $url = $line->generatePKCELoginUrl([ // Callback URL: https://developers.line.biz/console/channel/<channel id>/line-login 'https://yourdomain.com', // Permissions requested from the user: https://developers.line.biz/en/docs/line-login/integrate-line-login/#scopes [ 'profile', 'openid', 'email' ], $codeVerifier, $codeChallenge ]); // or $url = $line->generatePKCELoginUrl([ // Callback URL: https://developers.line.biz/console/channel/<channel id>/line-login 'redirect_uri' => $url, // Permissions requested from the user: https://developers.line.biz/en/docs/line-login/integrate-line-login/#scopes 'scope' => ['openid', 'openid'], 'state' => $codeVerifier, 'code_challenge' => $codeChallenge, ]);
- command