Merge branch 'master' of github.com:appwrite/appwrite into restify
This commit is contained in:
commit
8f6b5ddf22
15 changed files with 615 additions and 8 deletions
|
@ -95,6 +95,8 @@ Below is a list of currently supported platforms and languages. If you wish to h
|
||||||
* ✅ [JS](https://github.com/appwrite/sdk-for-js) (Maintained by the Appwrite Team)
|
* ✅ [JS](https://github.com/appwrite/sdk-for-js) (Maintained by the Appwrite Team)
|
||||||
* ✅ [NodeJS](https://github.com/appwrite/sdk-for-node) (Maintained by the Appwrite Team)
|
* ✅ [NodeJS](https://github.com/appwrite/sdk-for-node) (Maintained by the Appwrite Team)
|
||||||
* ✅ [PHP](https://github.com/appwrite/sdk-for-php) (Maintained by the Appwrite Team)
|
* ✅ [PHP](https://github.com/appwrite/sdk-for-php) (Maintained by the Appwrite Team)
|
||||||
|
* ✅ [Go](https://github.com/appwrite/sdk-for-go) **Work in progress** (Maintained by the Appwrite Team)
|
||||||
|
* ✅ [Dart](https://github.com/appwrite/sdk-for-dart) **Work in progress** (Maintained by the Appwrite Team)
|
||||||
* ✅ [Ruby](https://github.com/appwrite/sdk-for-ruby) - **Work in progress** (Maintained by the Appwrite Team)
|
* ✅ [Ruby](https://github.com/appwrite/sdk-for-ruby) - **Work in progress** (Maintained by the Appwrite Team)
|
||||||
* ✅ [Python](https://github.com/appwrite/sdk-for-python) - **Work in progress** (Maintained by the Appwrite Team)
|
* ✅ [Python](https://github.com/appwrite/sdk-for-python) - **Work in progress** (Maintained by the Appwrite Team)
|
||||||
* ✳️ Looking for more SDKs? - Help us by contributing a pull request to our [SDK Generator](https://github.com/appwrite/sdk-generator)!
|
* ✳️ Looking for more SDKs? - Help us by contributing a pull request to our [SDK Generator](https://github.com/appwrite/sdk-generator)!
|
||||||
|
|
109
app/config/platforms.php
Normal file
109
app/config/platforms.php
Normal file
|
@ -0,0 +1,109 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
const APP_PLATFORM_WEB = 'web';
|
||||||
|
const APP_PLATFORM_IOS = 'ios';
|
||||||
|
const APP_PLATFORM_ANDROID = 'android';
|
||||||
|
const APP_PLATFORM_UNITY = 'unity';
|
||||||
|
const APP_PLATFORM_FLUTTER = 'flutter';
|
||||||
|
const APP_PLATFORM_SERVER = 'server';
|
||||||
|
|
||||||
|
return [
|
||||||
|
APP_PLATFORM_WEB => [
|
||||||
|
'name' => 'Web',
|
||||||
|
'enabled' => true,
|
||||||
|
'beta' => false,
|
||||||
|
'language' => [
|
||||||
|
[
|
||||||
|
'name' => 'JS',
|
||||||
|
'repository' => '',
|
||||||
|
'enabled' => true,
|
||||||
|
'beta' => false,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'TypeScript',
|
||||||
|
'repository' => '',
|
||||||
|
'enabled' => true,
|
||||||
|
'beta' => false,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
|
||||||
|
APP_PLATFORM_IOS => [
|
||||||
|
'name' => 'iOS',
|
||||||
|
'enabled' => false,
|
||||||
|
'beta' => false,
|
||||||
|
'language' => [
|
||||||
|
[
|
||||||
|
'name' => 'Swift',
|
||||||
|
'repository' => '',
|
||||||
|
'enabled' => false,
|
||||||
|
'beta' => false,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'Objective C',
|
||||||
|
'repository' => '',
|
||||||
|
'enabled' => false,
|
||||||
|
'beta' => false,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
|
||||||
|
APP_PLATFORM_ANDROID => [
|
||||||
|
'name' => 'Android',
|
||||||
|
'enabled' => false,
|
||||||
|
'beta' => false,
|
||||||
|
'language' => [
|
||||||
|
[
|
||||||
|
'name' => 'Swift',
|
||||||
|
'repository' => '',
|
||||||
|
'enabled' => false,
|
||||||
|
'beta' => false,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'Objective C',
|
||||||
|
'repository' => '',
|
||||||
|
'enabled' => false,
|
||||||
|
'beta' => false,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
|
||||||
|
APP_PLATFORM_SERVER => [
|
||||||
|
'name' => 'Server',
|
||||||
|
'enabled' => true,
|
||||||
|
'beta' => false,
|
||||||
|
'language' => [
|
||||||
|
[
|
||||||
|
'name' => 'Node.js',
|
||||||
|
'repository' => '',
|
||||||
|
'enabled' => true,
|
||||||
|
'beta' => false,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'PHP',
|
||||||
|
'repository' => '',
|
||||||
|
'enabled' => true,
|
||||||
|
'beta' => false,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'Python',
|
||||||
|
'repository' => '',
|
||||||
|
'enabled' => true,
|
||||||
|
'beta' => true,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'Go',
|
||||||
|
'repository' => '',
|
||||||
|
'enabled' => true,
|
||||||
|
'beta' => true,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'Ruby',
|
||||||
|
'repository' => '',
|
||||||
|
'enabled' => true,
|
||||||
|
'beta' => true,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
|
||||||
|
];
|
|
@ -115,12 +115,30 @@ return [
|
||||||
'enabled' => true,
|
'enabled' => true,
|
||||||
'mock' => false,
|
'mock' => false,
|
||||||
],
|
],
|
||||||
|
'yandex' => [
|
||||||
|
'developers' => 'https://tech.yandex.com/oauth/',
|
||||||
|
'icon' => 'icon-yandex',
|
||||||
|
'enabled' => true,
|
||||||
|
'mock' => false,
|
||||||
|
],
|
||||||
'twitter' => [
|
'twitter' => [
|
||||||
'developers' => 'https://developer.twitter.com/',
|
'developers' => 'https://developer.twitter.com/',
|
||||||
'icon' => 'icon-twitter',
|
'icon' => 'icon-twitter',
|
||||||
'enabled' => false,
|
'enabled' => false,
|
||||||
'mock' => false
|
'mock' => false
|
||||||
],
|
],
|
||||||
|
'paypal' => [
|
||||||
|
'developers' => 'https://developer.paypal.com/docs/api/overview/',
|
||||||
|
'icon' => 'icon-paypal',
|
||||||
|
'enabled' => true,
|
||||||
|
'mock' => false
|
||||||
|
],
|
||||||
|
'bitly' => [
|
||||||
|
'developers' => 'https://dev.bitly.com/v4_documentation.html',
|
||||||
|
'icon' => 'icon-bitly',
|
||||||
|
'enabled' => true,
|
||||||
|
'mock' => false
|
||||||
|
],
|
||||||
// Keep Last
|
// Keep Last
|
||||||
'mock' => [
|
'mock' => [
|
||||||
'developers' => 'https://appwrite.io',
|
'developers' => 'https://appwrite.io',
|
||||||
|
|
|
@ -180,7 +180,7 @@ $graph = $this->getParam('graph', false);
|
||||||
|
|
||||||
<p>After adding your new website, install our JS SDK to integrate with your code and read our <a href="/docs/getting-started-for-web" target="_blank">getting started</a> tutorial.</p>
|
<p>After adding your new website, install our JS SDK to integrate with your code and read our <a href="/docs/getting-started-for-web" target="_blank">getting started</a> tutorial.</p>
|
||||||
|
|
||||||
<div class="margin-bottom-no ide" data-lang="bash">
|
<div class="margin-bottom-no ide" data-lang="bash" data-lang-label="bash">
|
||||||
<pre class="line-numbers"><code class="prism language-bash" data-prism>npm install appwrite</code></pre>
|
<pre class="line-numbers"><code class="prism language-bash" data-prism>npm install appwrite</code></pre>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
2
public/dist/styles/default-ltr.css
vendored
2
public/dist/styles/default-ltr.css
vendored
File diff suppressed because one or more lines are too long
2
public/dist/styles/default-rtl.css
vendored
2
public/dist/styles/default-rtl.css
vendored
File diff suppressed because one or more lines are too long
BIN
public/images/oauth/bitly.png
Normal file
BIN
public/images/oauth/bitly.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.6 KiB |
BIN
public/images/oauth/paypal.png
Normal file
BIN
public/images/oauth/paypal.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.4 KiB |
BIN
public/images/oauth/yandex.png
Normal file
BIN
public/images/oauth/yandex.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.2 KiB |
|
@ -16,7 +16,7 @@ https://prismjs.com/download.html#themes=prism-okaidia&languages=markup+css+clik
|
||||||
margin-bottom: 30px;
|
margin-bottom: 30px;
|
||||||
|
|
||||||
&[data-lang]::after {
|
&[data-lang]::after {
|
||||||
content: attr(data-lang);
|
content: attr(data-lang-label);
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
background: #ffffff;
|
background: #ffffff;
|
||||||
color: #000000;
|
color: #000000;
|
||||||
|
|
|
@ -600,6 +600,18 @@
|
||||||
"code": 59462,
|
"code": 59462,
|
||||||
"src": "entypo"
|
"src": "entypo"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"uid": "94089b37297572e936b0943bcfa041d3",
|
||||||
|
"css": "angle-circled-right",
|
||||||
|
"code": 61752,
|
||||||
|
"src": "fontawesome"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"uid": "8933c2579166c2ee56ae40dc6a0b4dc6",
|
||||||
|
"css": "angle-circled-left",
|
||||||
|
"code": 61751,
|
||||||
|
"src": "fontawesome"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"uid": "f5896a5c224ad6c2a1fb92456bb8a211",
|
"uid": "f5896a5c224ad6c2a1fb92456bb8a211",
|
||||||
"css": "c",
|
"css": "c",
|
||||||
|
|
File diff suppressed because one or more lines are too long
151
src/Auth/OAuth/Bitly.php
Normal file
151
src/Auth/OAuth/Bitly.php
Normal file
|
@ -0,0 +1,151 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Auth\OAuth;
|
||||||
|
|
||||||
|
use Auth\OAuth;
|
||||||
|
|
||||||
|
// Reference Material
|
||||||
|
// https://dev.bitly.com/v4_documentation.html
|
||||||
|
//
|
||||||
|
class Bitly extends OAuth
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $endpoint = 'https://bitly.com/oauth/';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $resourceEndpoint = 'https://api-ssl.bitly.com/';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $scopes = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $user = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getName():string
|
||||||
|
{
|
||||||
|
return 'bitly';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getLoginURL():string
|
||||||
|
{
|
||||||
|
return $this->endpoint . 'authorize?'.
|
||||||
|
http_build_query([
|
||||||
|
'client_id' => $this->appID,
|
||||||
|
'redirect_uri' => $this->callback,
|
||||||
|
'state' => json_encode($this->state)
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $code
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getAccessToken(string $code):string
|
||||||
|
{
|
||||||
|
$response = $this->request(
|
||||||
|
'POST',
|
||||||
|
$this->resourceEndpoint . 'oauth/access_token',
|
||||||
|
["Content-Type: application/x-www-form-urlencoded"],
|
||||||
|
http_build_query([
|
||||||
|
"client_id" => $this->appID,
|
||||||
|
"client_secret" => $this->appSecret,
|
||||||
|
"code" => $code,
|
||||||
|
"redirect_uri" => $this->callback,
|
||||||
|
"state" => json_encode($this->state)
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
$result = null;
|
||||||
|
|
||||||
|
if ($response) {
|
||||||
|
parse_str($response, $result);
|
||||||
|
return $result['access_token'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $accessToken
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getUserID(string $accessToken):string
|
||||||
|
{
|
||||||
|
$user = $this->getUser($accessToken);
|
||||||
|
|
||||||
|
if (isset($user['login'])) {
|
||||||
|
return $user['login'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $accessToken
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getUserEmail(string $accessToken):string
|
||||||
|
{
|
||||||
|
$user = $this->getUser($accessToken);
|
||||||
|
|
||||||
|
if (isset($user['emails'])) {
|
||||||
|
return $user['emails'][0]['email'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $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)
|
||||||
|
{
|
||||||
|
$headers = [
|
||||||
|
'Authorization: Bearer '. urlencode($accessToken),
|
||||||
|
"Accept: application/json"
|
||||||
|
];
|
||||||
|
|
||||||
|
if (empty($this->user)) {
|
||||||
|
$this->user = json_decode($this->request('GET', $this->resourceEndpoint . "v4/user", $headers), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return $this->user;
|
||||||
|
}
|
||||||
|
}
|
164
src/Auth/OAuth/Paypal.php
Normal file
164
src/Auth/OAuth/Paypal.php
Normal file
|
@ -0,0 +1,164 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Auth\OAuth;
|
||||||
|
|
||||||
|
use Auth\OAuth;
|
||||||
|
|
||||||
|
// Reference Material
|
||||||
|
// https://developer.paypal.com/docs/api/overview/
|
||||||
|
|
||||||
|
class Paypal extends OAuth
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $endpoint= [
|
||||||
|
'sandbox' => 'https://www.sandbox.paypal.com/',
|
||||||
|
'live' => 'https://www.paypal.com/',
|
||||||
|
];
|
||||||
|
|
||||||
|
private $resourceEndpoint = [
|
||||||
|
'sandbox' => 'https://api.sandbox.paypal.com/v1/',
|
||||||
|
'live' => 'https://api.paypal.com/v1/',
|
||||||
|
];
|
||||||
|
|
||||||
|
private $environment = 'live';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $user = [];
|
||||||
|
|
||||||
|
|
||||||
|
protected $scopes = [
|
||||||
|
'openid',
|
||||||
|
'profile',
|
||||||
|
'email'
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getName(): string
|
||||||
|
{
|
||||||
|
return 'paypal';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getLoginURL(): string
|
||||||
|
{
|
||||||
|
$url = $this->endpoint[$this->environment] . 'connect/?'.
|
||||||
|
http_build_query([
|
||||||
|
'flowEntry' => 'static',
|
||||||
|
'response_type' => 'code',
|
||||||
|
'client_id' => $this->appID,
|
||||||
|
'scope' => implode(' ', $this->getScopes()),
|
||||||
|
// paypal is not accepting localhost string into return uri
|
||||||
|
'redirect_uri' => str_replace("localhost", "127.0.0.1", $this->callback),
|
||||||
|
'state' => json_encode($this->state),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $url;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $code
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getAccessToken(string $code): string
|
||||||
|
{
|
||||||
|
$accessToken = $this->request(
|
||||||
|
'POST',
|
||||||
|
$this->resourceEndpoint[$this->environment] . 'oauth2/token',
|
||||||
|
['Authorization: Basic ' . base64_encode($this->appID . ':' . $this->appSecret)],
|
||||||
|
http_build_query([
|
||||||
|
'code' => $code,
|
||||||
|
'grant_type' => 'authorization_code',
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
$accessToken = json_decode($accessToken, true);
|
||||||
|
|
||||||
|
|
||||||
|
if (isset($accessToken['access_token'])) {
|
||||||
|
return $accessToken['access_token'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $accessToken
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getUserID(string $accessToken): string
|
||||||
|
{
|
||||||
|
$user = $this->getUser($accessToken);
|
||||||
|
|
||||||
|
if (isset($user['payer_id'])) {
|
||||||
|
return $user['payer_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $accessToken
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getUserEmail(string $accessToken): string
|
||||||
|
{
|
||||||
|
$user = $this->getUser($accessToken);
|
||||||
|
|
||||||
|
if (isset($user['emails'])) {
|
||||||
|
return $user['emails'][0]['value'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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
|
||||||
|
{
|
||||||
|
$header = [
|
||||||
|
'Content-Type: application/json',
|
||||||
|
'Authorization: Bearer '.urlencode($accessToken),
|
||||||
|
];
|
||||||
|
if (empty($this->user)) {
|
||||||
|
$user = $this->request(
|
||||||
|
'GET',
|
||||||
|
$this->resourceEndpoint[$this->environment] . 'identity/oauth2/userinfo?schema=paypalv1.1',
|
||||||
|
$header
|
||||||
|
);
|
||||||
|
$this->user = json_decode($user, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->user;
|
||||||
|
}
|
||||||
|
}
|
150
src/Auth/OAuth/Yandex.php
Normal file
150
src/Auth/OAuth/Yandex.php
Normal file
|
@ -0,0 +1,150 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Auth\OAuth;
|
||||||
|
|
||||||
|
use Auth\OAuth;
|
||||||
|
|
||||||
|
// Reference Material
|
||||||
|
// https://tech.yandex.com/passport/doc/dg/reference/request-docpage/
|
||||||
|
// https://tech.yandex.com/oauth/doc/dg/reference/web-client-docpage/
|
||||||
|
|
||||||
|
|
||||||
|
class Yandex extends OAuth
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $user = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $scopes = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getName(): string
|
||||||
|
{
|
||||||
|
return 'Yandex';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $state
|
||||||
|
*
|
||||||
|
* @return json
|
||||||
|
*/
|
||||||
|
public function parseState(string $state)
|
||||||
|
{
|
||||||
|
return json_decode(html_entity_decode($state), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getLoginURL(): string
|
||||||
|
{
|
||||||
|
return 'https://oauth.yandex.com/authorize?'.http_build_query([
|
||||||
|
'response_type' => 'code',
|
||||||
|
'client_id' => $this->appID,
|
||||||
|
'scope'=> implode(' ', $this->getScopes()),
|
||||||
|
'state' => json_encode($this->state)
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $code
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getAccessToken(string $code): string
|
||||||
|
{
|
||||||
|
$headers = [
|
||||||
|
"Authorization: Basic " . base64_encode($this->appID . ":" . $this->appSecret),
|
||||||
|
"Content-Type: application/x-www-form-urlencoded",
|
||||||
|
];
|
||||||
|
|
||||||
|
$accessToken = $this->request(
|
||||||
|
'POST',
|
||||||
|
'https://oauth.yandex.com/token',
|
||||||
|
$headers,
|
||||||
|
http_build_query([
|
||||||
|
'code' => $code,
|
||||||
|
'grant_type' => 'authorization_code'
|
||||||
|
])
|
||||||
|
);
|
||||||
|
$accessToken = json_decode($accessToken, true);
|
||||||
|
|
||||||
|
if (isset($accessToken['access_token'])) {
|
||||||
|
return $accessToken['access_token'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $accessToken
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getUserID(string $accessToken): string
|
||||||
|
{
|
||||||
|
$user = $this->getUser($accessToken);
|
||||||
|
|
||||||
|
if (isset($user['id'])) {
|
||||||
|
return $user['id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $accessToken
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getUserEmail(string $accessToken): string
|
||||||
|
{
|
||||||
|
$user = $this->getUser($accessToken);
|
||||||
|
|
||||||
|
if (isset($user['default_email'])) {
|
||||||
|
return $user['default_email'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $accessToken
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getUserName(string $accessToken): string
|
||||||
|
{
|
||||||
|
$user = $this->getUser($accessToken);
|
||||||
|
|
||||||
|
if (isset($user['display_name'])) {
|
||||||
|
return $user['display_name'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $accessToken
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function getUser(string $accessToken): array
|
||||||
|
{
|
||||||
|
if (empty($this->user)) {
|
||||||
|
$user = $this->request('GET', 'https://login.yandex.ru/info?'.http_build_query([
|
||||||
|
'format' => 'json',
|
||||||
|
'oauth_token' => $accessToken
|
||||||
|
]));
|
||||||
|
$this->user = json_decode($user, true);
|
||||||
|
}
|
||||||
|
return $this->user;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue