SDK of the LINE Login API for PHP

Overview

LINE Login for PHP

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

MIT

You might also like...
An SDK built to facilitate application development for Facebook Ads API.

Facebook Business SDK for PHP Introduction The Facebook Business SDK is a one-stop shop to help our partners better serve their businesses. Partners a

ExchangeRatesAPI - Currency Exchange Rates API SDK

ExchangeRatesAPI - Currency Exchange Rates API SDK This is an unofficial wrapper for the awesome, free ExchangeRatesAPI, which provides exchange rate

Facebook SDK for PHP (v6) - allows you to access the Facebook Platform from your PHP app

Facebook SDK for PHP (v6) This repository contains the open source PHP SDK that allows you to access the Facebook Platform from your PHP app. Installa

Unofficial Firebase Admin SDK for PHP

Firebase Admin PHP SDK Table of Contents Overview Installation Documentation Support License Overview Firebase provides the tools and infrastructure y

Notion PHP SDK
Notion PHP SDK

Notion PHP SDK This is an unofficial PHP SDK for the new public Notion API. It's work in progress as we didn't get the change to be included to the pr

爱发电非官方简易 PHP SDK

afdian-php-sdk 爱发电非官方简易 PHP SDK by Akkariin 这是一个简单的 SDK,可以用于查询爱发电的订单和赞助者信息 Installation 将项目 clone 到本地即可 git clone https://github.com/ZeroDream-CN/afdi

AWS Cognito package using the AWS SDK for PHP/Laravel
AWS Cognito package using the AWS SDK for PHP/Laravel

Laravel Package to manage Web and API authentication with AWS Cognito AWS Cognito package using the AWS SDK for PHP This package provides a simple way

PHP SDK to interact with the Casper Network nodes via RPC

casper-php-sdk PHP SDK to interact with Casper Network nodes via RPC Install composer require make-software/casper-php-sdk Examples RPC Client: $node

A Laravel 5+ (and 4) service provider for the AWS SDK for PHP

AWS Service Provider for Laravel 5/6/7/8 This is a simple Laravel service provider for making it easy to include the official AWS SDK for PHP in your

Zoho CRM API SDK is a wrapper to Zoho CRM APIs. By using this sdk, user can build the application with ease

Archival Notice: This SDK is archived. You can continue to use it, but no new features or support requests will be accepted. For the new version, refe

null 81 Nov 4, 2022
Shopware PHP SDK is a simple SDK implementation of Shopware 6 APIs

Shopware PHP SDK is a simple SDK implementation of Shopware 6 APIs. It helps to access the API in an object-oriented way.

Thuong Le 77 Dec 19, 2022
The 1Password Connect PHP SDK provides your PHP applications access to the 1Password Connect API hosted on your infrastructure and leverage the power of 1Password Secrets Automation

1Password Connect PHP SDK The 1Password Connect PHP SDK provides your PHP applications access to the 1Password Connect API hosted on your infrastructu

Michelangelo van Dam 12 Dec 26, 2022
Esse SDK em PHP foi desenvolvido no intuito de tornar mais prático a integração com nossa API.

Sobre Beedoo SDK Acessar documentação completa da Beedoo API. A API é organizada seguindo a arquitetura REST, boas práticas, convenções e padrões como

Beedoo Edtech 5 Dec 2, 2021
A PHP SDK for accessing the OpenAI GPT-3 API

OpenAI GPT-3 Api Client in PHP Installation You can install the package via composer: composer require orhanerday/open-ai Usage use Orhanerday\OpenAi\

Orhan erday 462 Jan 2, 2023
PHP SDK for the Sellix Developers API (developers.sellix.io)

PHP SDK for the Sellix Developers API (developers.sellix.io). Quickly get started and create products, payments and more using PHP.

Sellix 7 Nov 23, 2022
Mark Sign - Gateway API PHP SDK

Mark Sign - Gateway API PHP SDK

Mark Sign 3 Feb 22, 2022
Light PHP SDK to interact with the Doma(in)Validity API.

Doma(in)Validity PHP SDK. Light PHP SDK to interact with the Doma(in)Validity API. Usage <?php require_once 'vendor/autoload.php'; use Domainvalidit

Doma(In)Validity 2 May 3, 2022
A PHP SDK for the ScreenshotOne.com API to take screenshots of any URL

phpsdk An official Screenshot API client for PHP. It takes minutes to start taking screenshots. Just sign up to get access and secret keys, import the

ScreenshotOne.com 4 Jun 14, 2022
BT Open API SDK in PHP

Mosel, a sdk package for BT open APIs This package is still under construction (july 13th 2022). Open Api are described in the Bouygues Telecom Develo

BboxLab 0 Jul 7, 2022