mirror of
https://github.com/appwrite/appwrite
synced 2026-05-22 08:28:42 +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.location', true)
|
||||
->label('sdk.cookies', true)
|
||||
->label('abuse-limit', 50)
|
||||
->label('abuse-key', 'ip:{ip}')
|
||||
// ->label('abuse-limit', 100)
|
||||
// ->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('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.')
|
||||
|
|
@ -435,8 +435,8 @@ $utopia->get('/v1/auth/login/oauth/callback/:provider/:projectId')
|
|||
->desc('OAuth Callback')
|
||||
->label('error', __DIR__.'/../views/general/error.phtml')
|
||||
->label('scope', 'auth')
|
||||
->label('abuse-limit', 50)
|
||||
->label('abuse-key', 'ip:{ip}')
|
||||
// ->label('abuse-limit', 100)
|
||||
// ->label('abuse-key', 'ip:{ip}')
|
||||
->label('docs', false)
|
||||
->param('projectId', '', function () { return new Text(1024); }, 'Project unique ID')
|
||||
->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('webhook', 'auth.oauth')
|
||||
->label('scope', 'auth')
|
||||
->label('abuse-limit', 50)
|
||||
->label('abuse-key', 'ip:{ip}')
|
||||
// ->label('abuse-limit', 100)
|
||||
// ->label('abuse-key', 'ip:{ip}')
|
||||
->label('docs', false)
|
||||
->param('provider', '', function () use ($providers) { return new WhiteList(array_keys($providers)); }, 'OAuth provider')
|
||||
->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) {
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ abstract class OAuth
|
|||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $scopes;
|
||||
protected $userScopes;
|
||||
|
||||
/**
|
||||
* OAuth constructor.
|
||||
|
|
@ -36,15 +36,15 @@ abstract class OAuth
|
|||
* @param string $appSecret
|
||||
* @param string $callback
|
||||
* @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->appSecret = $appSecret;
|
||||
$this->callback = $callback;
|
||||
$this->state = $state;
|
||||
$this->scopes = $scopes;
|
||||
$this->userScopes = $userScopes;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -92,8 +92,8 @@ abstract class OAuth
|
|||
*/
|
||||
protected function addScope(string $scope){
|
||||
// Add a scope to the scopes array if it isn't already present
|
||||
if (!in_array($scope, $this->scopes)){
|
||||
$this->$scopes[] = $scope;
|
||||
if (!in_array($scope, $this->userScopes)){
|
||||
$this->userScopes[] = $scope;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -101,10 +101,10 @@ abstract class OAuth
|
|||
* @return array
|
||||
*/
|
||||
protected function getScopes(){
|
||||
return $this->scopes;
|
||||
return $this->userScopes;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 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
|
||||
// json_decoding
|
||||
|
|
|
|||
|
|
@ -14,6 +14,11 @@ class Bitbucket extends OAuth
|
|||
*/
|
||||
protected $user = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $requiredScope = [];
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
|
|
@ -27,10 +32,20 @@ class Bitbucket extends OAuth
|
|||
*/
|
||||
public function getLoginURL(): string
|
||||
{
|
||||
return 'https://bitbucket.org/site/oauth2/authorize?' .
|
||||
'client_id=' . urlencode($this->appID).
|
||||
'&state=' . urlencode(json_encode($this->state)).
|
||||
'&response_type=code';
|
||||
// add each required scope to the user scopes and pass $this->scopes to the query builder
|
||||
// var_dump($this->getScopes());
|
||||
foreach ($this->requiredScope as $item) {
|
||||
$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