ejlin/line-login-sdk-php
最新稳定版本:0.1.2
Composer 安装命令:
composer require ejlin/line-login-sdk-php
包简介
SDK of the LINE Login API for PHP
README 文档
README
SDK of the LINE Login API for PHP
Documentation
See the official API documentation for more information.
Installation
Use the package manager composer to install package.
composer require ejlin/line-login-sdk-php
Usage
###Pure PHP version:
$httpClient = new \EJLin\LINELogin\GuzzleHTTPClient(); // Channel Basic Information: https://developers.line.biz/console/channel/<channel id>/basics $LINELogin = new \EJLin\LINELogin($httpClient, ['clientId' => '<channel id>','clientSecret' => '<channel secret>']); // Step 3. After login, the LINE will redirect to the URL that you requested with state and code if(isset($_GET['code']) && isset($_GET['state'])) { // TODO: Check the state code same as what you requested // Request access token from the LINE platform $token = $LINELogin->requestToken( 'https://yourdomain.com', // The url must be the same as requested $_GET['code'] // Each code only can request a token once ); // Get user profile from the LINE platform $userProfile = $LINELogin->getUserProfile($token); printf("Hello %s !",$userProfile->getDisplayName()); exit; } // A unique alphanumeric string used to prevent cross-site request forgery $state = \EJLin\LINELogin\Helper::randomString(40); // Step 1. Make authorize url $authorizeUrl = $LINELogin->makeAuthorizeUrl( 'https://yourdomain.com', // Callback URL: https://developers.line.biz/console/channel/<channel id>/line-login 'profile openid email', // Permissions requested from the user: https://developers.line.biz/en/docs/line-login/integrate-line-login/#scopes $state ); // Step 2. Redirect to authorize url header("Location: $authorizeUrl"); exit;
###Laravel support:
After installed, add LINE_LOGIN_CHANNEL_ID and LINE_LOGIN_CHANNEL_SECRET to .env
LINE_LOGIN_CHANNEL_ID=<channel id>
LINE_LOGIN_CHANNEL_SECRET=<channel secret>
then you can use LINELogin and LINELoginHelper facades like following.
// Step 3. if(request()->has('code') && request()->has('state')) { $token = \EJLin\Laravel\Facades\LINELogin::requestToken( url()->current(), request()->input('code'), ); $userProfile = \EJLin\Laravel\Facades\LINELogin::getUserProfile($token); return "Hello {$userProfile->getDisplayName()} !"; } $state = \EJLin\Laravel\Facades\LINELoginHelper::randomString(40); // Step 1. $authorizeUrl = \EJLin\Laravel\Facades\LINELogin::makeAuthorizeUrl( url()->current(), 'profile openid email', $state ); // Step 2. return redirect()->away($authorizeUrl);
Reference
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
License
统计信息
- 总下载量: 385
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-10-30