feat: removed VK since they do not expose email anymore

This commit is contained in:
Christy Jacob
2022-05-05 14:49:04 +04:00
parent e253809f7e
commit 324eebcbf8
5 changed files with 2 additions and 215 deletions
-10
View File
@@ -241,16 +241,6 @@ return [ // Ordered by ABC.
'beta' => false,
'mock' => false,
],
'vk' => [
'name' => 'VK',
'developers' => 'https://vk.com/dev',
'icon' => 'icon-vk',
'enabled' => true,
'sandbox' => false,
'form' => false,
'beta' => false,
'mock' => false,
],
'zoom' => [
'name' => 'Zoom',
'developers' => 'https://marketplace.zoom.us/docs/guides/auth/oauth/',
Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

+1 -1
View File
@@ -179,7 +179,7 @@ class Bitbucket extends OAuth2
$emails = \json_decode($emails, true);
if (isset($emails['values'])) {
foreach ($emails['values'] as $email) {
if ($email['is_primary']) {
if ($email['is_confirmed']) {
$this->user['email'] = $email['email'];
$this->user['is_confirmed'] = $email['is_confirmed'];
break;
-203
View File
@@ -1,203 +0,0 @@
<?php
namespace Appwrite\Auth\OAuth2;
use Appwrite\Auth\OAuth2;
use Utopia\Exception;
// Reference Material
// https://vk.com/dev/first_guide
// https://vk.com/dev/auth_sites
// https://vk.com/dev/api_requests
// https://plugins.miniorange.com/guide-to-configure-vkontakte-as-oauth-server
class Vk extends OAuth2
{
/**
* @var array
*/
protected $user = [];
/**
* @var array
*/
protected $tokens = [];
/**
* @var array
*/
protected $scopes = [
'openid',
'email'
];
/**
* @var string
*/
protected $version = '5.101';
/**
* @return string
*/
public function getName(): string
{
return 'vk';
}
/**
* @return string
*/
public function getLoginURL(): string
{
return 'https://oauth.vk.com/authorize?' . \http_build_query([
'client_id' => $this->appID,
'redirect_uri' => $this->callback,
'response_type' => 'code',
'state' => \json_encode($this->state),
'v' => $this->version,
'scope' => \implode(' ', $this->getScopes())
]);
}
/**
* @param string $code
*
* @return array
*/
protected function getTokens(string $code): array
{
if(empty($this->tokens)) {
$headers = ['Content-Type: application/x-www-form-urlencoded;charset=UTF-8'];
$this->tokens = \json_decode($this->request(
'POST',
'https://oauth.vk.com/access_token?',
$headers,
\http_build_query([
'code' => $code,
'client_id' => $this->appID,
'client_secret' => $this->appSecret,
'redirect_uri' => $this->callback
])
), true);
$this->user['email'] = $this->tokens['email'];
$this->user['user_id'] = $this->tokens['user_id'];
}
return $this->tokens;
}
/**
* @param string $refreshToken
*
* @return array
*/
public function refreshTokens(string $refreshToken):array
{
$headers = ['Content-Type: application/x-www-form-urlencoded;charset=UTF-8'];
$this->tokens = \json_decode($this->request(
'POST',
'https://oauth.vk.com/access_token?',
$headers,
\http_build_query([
'refresh_token' => $refreshToken,
'client_id' => $this->appID,
'client_secret' => $this->appSecret,
'grant_type' => 'refresh_token'
])
), true);
if(empty($this->tokens['refresh_token'])) {
$this->tokens['refresh_token'] = $refreshToken;
}
$this->user['email'] = $this->tokens['email'];
$this->user['user_id'] = $this->tokens['user_id'];
return $this->tokens;
}
/**
* @param string $accessToken
*
* @return string
*/
public function getUserID(string $accessToken): string
{
$user = $this->getUser($accessToken);
if (isset($user['user_id'])) {
return $user['user_id'];
}
return '';
}
/**
* @param string $accessToken
*
* @return string
*/
public function getUserEmail(string $accessToken): string
{
$user = $this->getUser($accessToken);
if (isset($user['email'])) {
return $user['email'];
}
return '';
}
/**
* Check if the OAuth email is verified
*
* @param $accessToken
*
* @return bool
*/
public function isEmailVerified(string $accessToken): bool
{
return false;
}
/**
* @param string $accessToken
*
* @return string
*/
public function getUserName(string $accessToken): string
{
$user = $this->getUser($accessToken);
if (isset($user['name'])) {
return $user['name'];
}
return '';
}
/**
* @param string $accessToken
*
* @return array
*/
protected function getUser(string $accessToken): array
{
if (empty($this->user['name'])) {
$user = $this->request(
'GET',
'https://api.vk.com/method/users.get?'. \http_build_query([
'v' => $this->version,
'fields' => 'id,name,email,first_name,last_name',
'access_token' => $accessToken
])
);
$user = \json_decode($user, true);
$this->user['name'] = $user['response'][0]['first_name'] ." ".$user['response'][0]['last_name'];
}
return $this->user;
}
}
+1 -1
View File
@@ -133,7 +133,7 @@ class Yammer extends OAuth2
/**
* Check if the OAuth email is verified
*
* If present, the email is verified.
* If present, the email is verified. This was verfied through a manual Yammer sign up process
*
* @param $accessToken
*