wilkques/line-login-sdk-php

LINE Login SDK for PHP

v5.1.1 2023-07-25 07:50 UTC

This package is auto-updated.

Last update: 2024-10-25 07:26:59 UTC


README

Latest Stable Version License

Installation

composer require wilkques/line-login-sdk-php

Scopes

How to use

  1. 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']
    ]);
  2. PKCE Authorization

    1. command composer require wilkques/pkce-php
    2. 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,
      ]);

REFERENCE

  1. Official
  2. LINE Login Official
  3. PKCE support for LINE Login