mirror of
https://github.com/appwrite/appwrite
synced 2026-05-24 09:28:40 +00:00
feat: applied methods to adapters
This commit is contained in:
parent
230b039bbd
commit
074bf1ae50
4 changed files with 34 additions and 19 deletions
|
|
@ -396,8 +396,8 @@ $utopia->get('/v1/auth/login/oauth/:provider')
|
||||||
->label('sdk.description', '/docs/references/auth/login-oauth.md')
|
->label('sdk.description', '/docs/references/auth/login-oauth.md')
|
||||||
->label('sdk.location', true)
|
->label('sdk.location', true)
|
||||||
->label('sdk.cookies', true)
|
->label('sdk.cookies', true)
|
||||||
->label('abuse-limit', 50)
|
// ->label('abuse-limit', 100)
|
||||||
->label('abuse-key', 'ip:{ip}')
|
// ->label('abuse-key', 'ip:{ip}')
|
||||||
->param('provider', '', function () use ($providers) { return new WhiteList(array_keys($providers)); }, 'OAuth Provider. Currently, supported providers are: ' . implode(', ', array_keys($providers)))
|
->param('provider', '', function () use ($providers) { return new WhiteList(array_keys($providers)); }, 'OAuth Provider. Currently, supported providers are: ' . implode(', ', array_keys($providers)))
|
||||||
->param('success', '', function () use ($clients) { return new Host($clients); }, 'URL to redirect back to your app after a successful login attempt.')
|
->param('success', '', function () use ($clients) { return new Host($clients); }, 'URL to redirect back to your app after a successful login attempt.')
|
||||||
->param('failure', '', function () use ($clients) { return new Host($clients); }, 'URL to redirect back to your app after a failed login attempt.')
|
->param('failure', '', function () use ($clients) { return new Host($clients); }, 'URL to redirect back to your app after a failed login attempt.')
|
||||||
|
|
@ -435,8 +435,8 @@ $utopia->get('/v1/auth/login/oauth/callback/:provider/:projectId')
|
||||||
->desc('OAuth Callback')
|
->desc('OAuth Callback')
|
||||||
->label('error', __DIR__.'/../views/general/error.phtml')
|
->label('error', __DIR__.'/../views/general/error.phtml')
|
||||||
->label('scope', 'auth')
|
->label('scope', 'auth')
|
||||||
->label('abuse-limit', 50)
|
// ->label('abuse-limit', 100)
|
||||||
->label('abuse-key', 'ip:{ip}')
|
// ->label('abuse-key', 'ip:{ip}')
|
||||||
->label('docs', false)
|
->label('docs', false)
|
||||||
->param('projectId', '', function () { return new Text(1024); }, 'Project unique ID')
|
->param('projectId', '', function () { return new Text(1024); }, 'Project unique ID')
|
||||||
->param('provider', '', function () use ($providers) { return new WhiteList(array_keys($providers)); }, 'OAuth provider')
|
->param('provider', '', function () use ($providers) { return new WhiteList(array_keys($providers)); }, 'OAuth provider')
|
||||||
|
|
@ -454,8 +454,8 @@ $utopia->get('/v1/auth/login/oauth/:provider/redirect')
|
||||||
->label('error', __DIR__.'/../views/general/error.phtml')
|
->label('error', __DIR__.'/../views/general/error.phtml')
|
||||||
->label('webhook', 'auth.oauth')
|
->label('webhook', 'auth.oauth')
|
||||||
->label('scope', 'auth')
|
->label('scope', 'auth')
|
||||||
->label('abuse-limit', 50)
|
// ->label('abuse-limit', 100)
|
||||||
->label('abuse-key', 'ip:{ip}')
|
// ->label('abuse-key', 'ip:{ip}')
|
||||||
->label('docs', false)
|
->label('docs', false)
|
||||||
->param('provider', '', function () use ($providers) { return new WhiteList(array_keys($providers)); }, 'OAuth provider')
|
->param('provider', '', function () use ($providers) { return new WhiteList(array_keys($providers)); }, 'OAuth provider')
|
||||||
->param('code', '', function () { return new Text(1024); }, 'OAuth code')
|
->param('code', '', function () { return new Text(1024); }, 'OAuth code')
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ global $utopia, $request, $response, $register, $user, $project;
|
||||||
|
|
||||||
$utopia->init(function () use ($utopia, $request, $response, $register, $user, $project) {
|
$utopia->init(function () use ($utopia, $request, $response, $register, $user, $project) {
|
||||||
if (is_null($project->getUid()) || Database::SYSTEM_COLLECTION_PROJECTS !== $project->getCollection()) {
|
if (is_null($project->getUid()) || Database::SYSTEM_COLLECTION_PROJECTS !== $project->getCollection()) {
|
||||||
throw new Exception('Missing Project UID', 400);
|
// throw new Exception('Missing Project UID', 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
$route = $utopia->match($request);
|
$route = $utopia->match($request);
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ abstract class OAuth
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $scopes;
|
protected $userScopes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OAuth constructor.
|
* OAuth constructor.
|
||||||
|
|
@ -36,15 +36,15 @@ abstract class OAuth
|
||||||
* @param string $appSecret
|
* @param string $appSecret
|
||||||
* @param string $callback
|
* @param string $callback
|
||||||
* @param array $state
|
* @param array $state
|
||||||
* @param array $scope
|
* @param array $userScopes
|
||||||
*/
|
*/
|
||||||
public function __construct(string $appId, string $appSecret, string $callback, $state = [], $scopes)
|
public function __construct(string $appId, string $appSecret, string $callback, $state = [], $userScopes = [])
|
||||||
{
|
{
|
||||||
$this->appID = $appId;
|
$this->appID = $appId;
|
||||||
$this->appSecret = $appSecret;
|
$this->appSecret = $appSecret;
|
||||||
$this->callback = $callback;
|
$this->callback = $callback;
|
||||||
$this->state = $state;
|
$this->state = $state;
|
||||||
$this->scopes = $scopes;
|
$this->userScopes = $userScopes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -92,8 +92,8 @@ abstract class OAuth
|
||||||
*/
|
*/
|
||||||
protected function addScope(string $scope){
|
protected function addScope(string $scope){
|
||||||
// Add a scope to the scopes array if it isn't already present
|
// Add a scope to the scopes array if it isn't already present
|
||||||
if (!in_array($scope, $this->scopes)){
|
if (!in_array($scope, $this->userScopes)){
|
||||||
$this->$scopes[] = $scope;
|
$this->userScopes[] = $scope;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -101,10 +101,10 @@ abstract class OAuth
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function getScopes(){
|
protected function getScopes(){
|
||||||
return $this->scopes;
|
return $this->userScopes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// The parseState function was designed specifically for Amazon OAuth Adapter to override.
|
// The parseState function was designed specifically for Amazon OAuth Adapter to override.
|
||||||
// The response from Amazon is html encoded and hence it needs to be html_decoded before
|
// The response from Amazon is html encoded and hence it needs to be html_decoded before
|
||||||
// json_decoding
|
// json_decoding
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,11 @@ class Bitbucket extends OAuth
|
||||||
*/
|
*/
|
||||||
protected $user = [];
|
protected $user = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $requiredScope = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
|
|
@ -27,10 +32,20 @@ class Bitbucket extends OAuth
|
||||||
*/
|
*/
|
||||||
public function getLoginURL(): string
|
public function getLoginURL(): string
|
||||||
{
|
{
|
||||||
return 'https://bitbucket.org/site/oauth2/authorize?' .
|
// add each required scope to the user scopes and pass $this->scopes to the query builder
|
||||||
'client_id=' . urlencode($this->appID).
|
// var_dump($this->getScopes());
|
||||||
'&state=' . urlencode(json_encode($this->state)).
|
foreach ($this->requiredScope as $item) {
|
||||||
'&response_type=code';
|
$this->addScope($item);
|
||||||
|
}
|
||||||
|
// var_dump($this->getScopes());
|
||||||
|
// exit();
|
||||||
|
|
||||||
|
return 'https://bitbucket.org/site/oauth2/authorize?' .http_build_query([
|
||||||
|
'response_type' => 'code',
|
||||||
|
'client_id' => $this->appID,
|
||||||
|
'scope' => implode(' ', $this->getScopes()),
|
||||||
|
'state' => json_encode($this->state),
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue