Compare commits

...
Author SHA1 Message Date
Everly Precia Suresh d1d70bf0c4 update branch 2022-12-07 17:02:01 +00:00
Everly Precia Suresh 0b4e62081d resolve conflicts 2022-12-07 16:59:29 +00:00
Everly Precia Suresh e552953c13 fix merge conflicts + update branch 2022-11-17 17:58:39 +00:00
Everly Precia Suresh d19ee461e6 style: run linter 2022-10-12 14:42:00 +00:00
Everly Precia Suresh 3e26cc56fd update changelog 2022-10-12 14:39:48 +00:00
Everly Precia Suresh d31a8e8182 refine LINE OAuth Implementation 2022-10-12 14:38:26 +00:00
Everly Precia SureshandGitHub 93f8470c9f add LINE PR to changelog 2022-10-11 22:47:03 +05:30
Everly Precia SureshandGitHub a11a1ee303 add LINE PR to changelog 2022-10-11 22:44:23 +05:30
Everly Precia Suresh 53e2c98f9f run : style linter 2022-10-11 16:37:46 +00:00
Everly Precia Suresh ed28c14ff7 Merge branch 'master' of https://github.com/appwrite/appwrite into feat-LINE-OAuth 2022-10-11 14:58:36 +00:00
Everly Precia Suresh c3ae2e0709 style: run linter 2022-10-11 14:56:54 +00:00
Everly Precia Suresh 0dab28b18e Merge branch 'master' of https://github.com/appwrite/appwrite into feat-LINE-OAuth 2022-10-10 19:06:43 +00:00
Everly Precia Suresh 8c18b9e1c3 bug fixes 2022-10-10 19:02:37 +00:00
Everly Precia Suresh 763510c37a debug login screen 2022-10-07 17:53:03 +00:00
Everly Precia Suresh 0b58184462 refine implementation 2022-10-07 16:56:38 +00:00
Everly Precia Suresh edc2c48c26 Merge branch 'master' of https://github.com/appwrite/appwrite into feat-LINE-OAuth 2022-10-03 15:35:42 +00:00
Everly Precia Suresh a998cd282b remove unecessary comment 2022-09-20 16:47:57 +00:00
Everly Precia Suresh bf0697454f Merge branch 'master' of https://github.com/appwrite/appwrite into feat-LINE-OAuth 2022-09-20 16:46:23 +00:00
Everly Precia Suresh 733913c105 implement isEmailVerified and getUserEmail 2022-09-20 16:45:26 +00:00
Everly Precia Suresh 96e9ea0146 Implement getUser method 2022-09-19 13:36:25 +00:00
Everly Precia Suresh e051cbcc87 Implement additional methods 2022-09-19 13:22:58 +00:00
Everly Precia Suresh 7dc555a65b Initial Implementation of LINE OAuth 2022-09-19 13:04:43 +00:00
4 changed files with 203 additions and 3 deletions
+5 -2
View File
@@ -1,5 +1,6 @@
- Fix invited account verified status [#4776](https://github.com/appwrite/appwrite/pull/4776)
- Get default region from environment on project create [#4780](https://github.com/appwrite/appwrite/pull/4780)
# Unreleased version
## Features
- Added LINE OAuth2 Provider [#4426](https://github.com/appwrite/appwrite/pull/4426)
# Version 1.1.2
## Changes
@@ -14,6 +15,8 @@
# Version 1.1.1
## Bugs
- Fix invited account verified status [#4776](https://github.com/appwrite/appwrite/pull/4776)
- Get default region from environment on project create [#4780](https://github.com/appwrite/appwrite/pull/4780)
- Fix Deletes worker using incorrect device for file deletion [#4662](https://github.com/appwrite/appwrite/pull/4662)
- Fix Migration for Stats adding the region attribute [#4704](https://github.com/appwrite/appwrite/pull/4704)
- Fix Migration stopping scheduled functions [#4704](https://github.com/appwrite/appwrite/pull/4704)
+10
View File
@@ -171,6 +171,16 @@ return [ // Ordered by ABC.
'beta' => false,
'mock' => false,
],
'line' => [
'name' => 'Line',
'developers' => 'https://developers.line.biz/en/docs/line-login/integrate-line-login/',
'icon' => 'icon-line',
'enabled' => true,
'sandbox' => false,
'form' => false,
'beta' => false,
'mock' => false,
],
'linkedin' => [
'name' => 'LinkedIn',
'developers' => 'https://developer.linkedin.com/',
+187
View File
@@ -0,0 +1,187 @@
<?php
namespace Appwrite\Auth\OAuth2;
use Appwrite\Auth\OAuth2;
class Line extends OAuth2
{
/**
* @var array
*/
protected array $user = [];
/**
* @var array
*/
protected array $tokens = [];
/**
* @var array
*/
protected array $scopes = [
'profile',
'openid',
'email',
];
/**
* @return string
*/
public function getName(): string
{
return 'line';
}
/**
* @return string
*/
public function getLoginURL(): string
{
return 'https://access.line.me/oauth2/v2.1/authorize?' . \http_build_query([
'client_id' => $this->appID,
'redirect_uri' => $this->callback,
'response_type' => 'code',
'scope' => \implode(' ', $this->getScopes()),
'state' => \json_encode($this->state)
]);
}
/**
* @param string $code
*
* @return array
*/
protected function getTokens(string $code): array
{
if (empty($this->tokens)) {
$this->tokens = \json_decode($this->request(
'POST',
'https://api.line.me/oauth2/v2.1/token',
['Content-Type: application/x-www-form-urlencoded'],
\http_build_query([
'grant_type' => 'authorization_code',
'code' => $code,
'redirect_uri' => $this->callback,
'client_id' => $this->appID,
'client_secret' => $this->appSecret,
])
), true);
}
return $this->tokens;
}
/**
* @param string $refreshToken
*
* @return array
*/
public function refreshTokens(string $refreshToken): array
{
$this->tokens = \json_decode($this->request(
'POST',
'https://api.line.me/oauth2/v2.1/token',
['Content-Type: application/x-www-form-urlencoded'],
\http_build_query([
'grant_type' => 'refresh_token',
'refresh_token' => $refreshToken,
'client_id' => $this->appID,
'client_secret' => $this->appSecret,
])
), true);
if (empty($this->tokens['refresh_token'])) {
$this->tokens['refresh_token'] = $refreshToken;
}
return $this->tokens;
}
/**
* @param string $accessToken
*
* @return string
*/
public function getUserID(string $accessToken): string
{
$user = $this->getUser($accessToken);
return $user['sub'] ?? '';
}
/**
* @param string $accessToken
*
* @return string
*/
public function getUserEmail(string $accessToken): string
{
$user = $this->getUser($accessToken);
return $user['email'] ?? '';
}
/**
* Check if the OAuth email is verified
*
* @link https://docs.github.com/en/rest/users/emails#list-email-addresses-for-the-authenticated-user
*
* @param string $accessToken
*
* @return bool
*/
public function isEmailVerified(string $accessToken): bool
{
$email = $this->getUserEmail($accessToken);
return !empty($email);
}
/**
* @param string $accessToken
*
* @return string
*/
public function getUserName(string $accessToken): string
{
$user = $this->getUser($accessToken);
return $user['name'] ?? '';
}
/**
* @param string $accessToken
*
* @return array
*/
protected function getUser(string $accessToken): array
{
if (empty($this->user)) {
$headers = ['Authorization: Bearer ' . \urlencode($accessToken)];
$user = $this->request('GET', 'https://api.line.me/oauth2/v2.1/userinfo', $headers);
$this->user = \json_decode($user, true);
$emailInfo = \json_decode($this->request(
'POST',
'https://api.line.me/oauth2/v2.1/verify',
['Content-Type: application/x-www-form-urlencoded'],
\http_build_query([
'id_token' => $this->tokens['id_token'],
'client_id' => $this->appID,
'client_secret' => $this->appSecret,
])
), true);
if (isset($emailInfo['email'])) {
$this->user['email'] = $emailInfo['email'];
}
}
return $this->user;
}
}