Merge branch 'master' of github.com:appwrite/appwrite
This commit is contained in:
commit
8c29879756
6 changed files with 177 additions and 0 deletions
|
@ -56,4 +56,9 @@ return [
|
|||
'icon' => 'icon-dropbox',
|
||||
'enabled' => true,
|
||||
],
|
||||
'apple' => [
|
||||
'developers' => 'https://www.dropbox.com/developers/documentation',
|
||||
'icon' => 'icon-apple',
|
||||
'enabled' => false,
|
||||
],
|
||||
];
|
||||
|
|
|
@ -381,6 +381,38 @@ $utopia->patch('/v1/users/:userId/status')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->patch('/v1/users/:userId/prefs')
|
||||
->desc('Update Account Prefs')
|
||||
->label('scope', 'users.write')
|
||||
->label('sdk.namespace', 'users')
|
||||
->label('sdk.method', 'updateUserPrefs')
|
||||
->param('userId', '', function () {
|
||||
return new UID();
|
||||
}, 'User unique ID.')
|
||||
->param('prefs', '', function () {
|
||||
return new \Utopia\Validator\Mock();
|
||||
}, 'Prefs key-value JSON object string.')
|
||||
->label('sdk.description', 'Update user preferences by its unique ID. You can pass only the specific settings you wish to update.')
|
||||
->action(
|
||||
function ($userId, $prefs) use ($response, $projectDB) {
|
||||
$user = $projectDB->getDocument($userId);
|
||||
|
||||
if (empty($user->getUid()) || Database::SYSTEM_COLLECTION_USERS != $user->getCollection()) {
|
||||
throw new Exception('User not found', 404);
|
||||
}
|
||||
|
||||
$user = $projectDB->updateDocument(array_merge($user->getArrayCopy(), [
|
||||
'prefs' => json_encode(array_merge(json_decode($user->getAttribute('prefs', '{}'), true), $prefs)),
|
||||
]));
|
||||
if (false === $user) {
|
||||
throw new Exception('Failed saving user to DB', 500);
|
||||
}
|
||||
|
||||
$response->json(array('result' => 'success'));
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
$utopia->delete('/v1/users/:userId/sessions/:session')
|
||||
->desc('Delete User Session')
|
||||
->label('scope', 'users.write')
|
||||
|
|
BIN
public/images/oauth/apple.png
Normal file
BIN
public/images/oauth/apple.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
133
src/Auth/OAuth/Apple.php
Normal file
133
src/Auth/OAuth/Apple.php
Normal file
|
@ -0,0 +1,133 @@
|
|||
<?php
|
||||
|
||||
namespace Auth\OAuth;
|
||||
|
||||
use Auth\OAuth;
|
||||
|
||||
// Reference Material
|
||||
// https://developer.okta.com/blog/2019/06/04/what-the-heck-is-sign-in-with-apple
|
||||
|
||||
class Apple extends OAuth
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $user = [];
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return 'apple';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getLoginURL(): string
|
||||
{
|
||||
return 'https://appleid.apple.com/auth/authorize?'.
|
||||
'client_id='.urlencode($this->appID).
|
||||
'&redirect_uri='.urlencode($this->callback).
|
||||
'&state='.urlencode(json_encode($this->state)).
|
||||
'&response_type=code'.
|
||||
'&response_mode=form_post'.
|
||||
'&scope=name+email';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAccessToken(string $code): string
|
||||
{
|
||||
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
|
||||
$accessToken = $this->request(
|
||||
'POST',
|
||||
'https://appleid.apple.com/auth/token',
|
||||
$headers,
|
||||
'code='.urlencode($code).
|
||||
'&client_id='.urlencode($this->appID).
|
||||
'&client_secret='.urlencode($this->appSecret).
|
||||
'&redirect_uri='.urlencode($this->callback).
|
||||
'&grant_type=authorization_code'
|
||||
);
|
||||
|
||||
var_dump($accessToken);
|
||||
exit();
|
||||
|
||||
$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['account_id'])) {
|
||||
return $user['account_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 '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $accessToken
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUserName(string $accessToken): string
|
||||
{
|
||||
$user = $this->getUser($accessToken);
|
||||
|
||||
if (isset($user['name'])) {
|
||||
return $user['name']['display_name'];
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $accessToken
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getUser(string $accessToken): array
|
||||
{
|
||||
if (empty($this->user)) {
|
||||
$headers[] = 'Authorization: Bearer '. urlencode($accessToken);
|
||||
$user = $this->request('POST', 'https://api.dropboxapi.com/2/users/get_current_account', $headers);
|
||||
$this->user = json_decode($user, true);
|
||||
}
|
||||
|
||||
return $this->user;
|
||||
}
|
||||
}
|
|
@ -4,6 +4,9 @@ namespace Auth\OAuth;
|
|||
|
||||
use Auth\OAuth;
|
||||
|
||||
// Reference Material
|
||||
// https://docs.gitlab.com/ee/api/oauth2.html
|
||||
|
||||
class Gitlab extends OAuth
|
||||
{
|
||||
/**
|
||||
|
|
|
@ -4,6 +4,10 @@ namespace Auth\OAuth;
|
|||
|
||||
use Auth\OAuth;
|
||||
|
||||
// Reference Material
|
||||
// https://developers.google.com/oauthplayground/
|
||||
// https://developers.google.com/identity/protocols/OAuth2
|
||||
// https://developers.google.com/identity/protocols/OAuth2WebServer
|
||||
class Google extends OAuth
|
||||
{
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue