mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
Merge pull request #13437 from appwrite/feat/gitlab-endpoint-env
feat: make the GitLab endpoint configurable
This commit is contained in:
8 files changed
+48
-10
No files matched your search
@@ -41,6 +41,7 @@ _APP_CONSOLE_GITHUB_APP_ID=
|
||||
_APP_CONSOLE_GITHUB_SECRET=
|
||||
_APP_CONSOLE_GITLAB_APP_ID=
|
||||
_APP_CONSOLE_GITLAB_SECRET=
|
||||
_APP_CONSOLE_GITLAB_ENDPOINT=
|
||||
_APP_CONSOLE_BITBUCKET_APP_ID=
|
||||
_APP_CONSOLE_BITBUCKET_SECRET=
|
||||
_APP_CONSOLE_GOOGLE_APP_ID=
|
||||
@@ -181,6 +182,7 @@ _APP_VCS_GITEA_BROWSER_ENDPOINT=http://localhost:9515
|
||||
_APP_VCS_GITEA_CLIENT_ID=
|
||||
_APP_VCS_GITEA_CLIENT_SECRET=
|
||||
_APP_VCS_GITEA_WEBHOOK_SECRET=gitea-webhook-secret
|
||||
_APP_VCS_GITLAB_ENDPOINT=
|
||||
_APP_VCS_GITLAB_CLIENT_ID=
|
||||
_APP_VCS_GITLAB_CLIENT_SECRET=
|
||||
_APP_VCS_GITLAB_WEBHOOK_SECRET=
|
||||
|
||||
@@ -59,7 +59,13 @@ $console = [
|
||||
'githubSecret' => System::getEnv('_APP_CONSOLE_GITHUB_SECRET', ''),
|
||||
'githubAppid' => System::getEnv('_APP_CONSOLE_GITHUB_APP_ID', ''),
|
||||
'gitlabEnabled' => true,
|
||||
'gitlabSecret' => System::getEnv('_APP_CONSOLE_GITLAB_SECRET', ''),
|
||||
// Auth\OAuth2\Gitlab reads its endpoint out of a JSON-encoded secret, so
|
||||
// _APP_CONSOLE_GITLAB_ENDPOINT travels with the credential. Stays empty when
|
||||
// unconfigured so account.php keeps reporting the provider as disabled.
|
||||
'gitlabSecret' => empty(System::getEnv('_APP_CONSOLE_GITLAB_SECRET', '')) ? '' : \json_encode([
|
||||
'clientSecret' => System::getEnv('_APP_CONSOLE_GITLAB_SECRET', ''),
|
||||
'endpoint' => System::getEnv('_APP_CONSOLE_GITLAB_ENDPOINT', 'https://gitlab.com'),
|
||||
]),
|
||||
'gitlabAppid' => System::getEnv('_APP_CONSOLE_GITLAB_APP_ID', ''),
|
||||
'bitbucketEnabled' => true,
|
||||
'bitbucketSecret' => System::getEnv('_APP_CONSOLE_BITBUCKET_SECRET', ''),
|
||||
|
||||
@@ -295,6 +295,15 @@ return [
|
||||
'question' => '',
|
||||
'filter' => ''
|
||||
],
|
||||
[
|
||||
'name' => '_APP_CONSOLE_GITLAB_ENDPOINT',
|
||||
'description' => 'URL of the GitLab instance used for signing in to the Appwrite console, for self-hosted GitLab. Defaults to https://gitlab.com when unset. This is separate from _APP_VCS_GITLAB_ENDPOINT, which powers repository integration rather than console sign-in.',
|
||||
'introduction' => '2.0.0',
|
||||
'default' => '',
|
||||
'required' => false,
|
||||
'question' => '',
|
||||
'filter' => ''
|
||||
],
|
||||
[
|
||||
'name' => '_APP_CONSOLE_BITBUCKET_APP_ID',
|
||||
'description' => 'Bitbucket OAuth consumer key used for signing in to the Appwrite console. You can find it in your Bitbucket workspace settings under OAuth consumers. This is separate from _APP_VCS_BITBUCKET_CLIENT_ID, which powers repository integration rather than console sign-in.',
|
||||
@@ -1572,6 +1581,15 @@ return [
|
||||
'question' => '',
|
||||
'filter' => ''
|
||||
],
|
||||
[
|
||||
'name' => '_APP_VCS_GITLAB_ENDPOINT',
|
||||
'description' => 'URL of your self-hosted GitLab instance, reachable from the Appwrite server and the browser. Defaults to https://gitlab.com when unset.',
|
||||
'introduction' => '2.0.0',
|
||||
'default' => '',
|
||||
'required' => false,
|
||||
'question' => '',
|
||||
'filter' => ''
|
||||
],
|
||||
[
|
||||
'name' => '_APP_VCS_GITLAB_CLIENT_ID',
|
||||
'description' => 'GitLab OAuth2 application client ID. You can generate one in your GitLab instance under Settings > Applications.',
|
||||
|
||||
+3
-2
@@ -8,6 +8,7 @@ use Appwrite\Auth\OAuth2\Bitbucket as OAuth2Bitbucket;
|
||||
use Appwrite\Auth\OAuth2\Gitea as OAuth2Gitea;
|
||||
use Appwrite\Auth\OAuth2\Github as OAuth2Github;
|
||||
use Appwrite\Auth\OAuth2\Gitlab as OAuth2Gitlab;
|
||||
use Utopia\System\System;
|
||||
use Utopia\VCS\Adapter\Git\Bitbucket;
|
||||
use Utopia\VCS\Adapter\Git\Gitea;
|
||||
use Utopia\VCS\Adapter\Git\GitHub;
|
||||
@@ -55,8 +56,8 @@ return [
|
||||
'clientSecret' => $clientSecret,
|
||||
'endpoint' => $endpoint,
|
||||
]), ''),
|
||||
// Only official gitlab.com is supported -- fixed, not configurable.
|
||||
'endpoint' => 'https://gitlab.com',
|
||||
// Defaults to gitlab.com; self-hosted installs point _APP_VCS_GITLAB_ENDPOINT at their own instance.
|
||||
'endpoint' => System::getEnv('_APP_VCS_GITLAB_ENDPOINT', 'https://gitlab.com'),
|
||||
'variables' => [
|
||||
'clientId' => ['required' => true, 'envVariable' => '_APP_VCS_GITLAB_CLIENT_ID'],
|
||||
'clientSecret' => ['required' => true, 'envVariable' => '_APP_VCS_GITLAB_CLIENT_SECRET'],
|
||||
|
||||
@@ -103,6 +103,7 @@ services:
|
||||
- _APP_CONSOLE_GITHUB_SECRET
|
||||
- _APP_CONSOLE_GITLAB_APP_ID
|
||||
- _APP_CONSOLE_GITLAB_SECRET
|
||||
- _APP_CONSOLE_GITLAB_ENDPOINT
|
||||
- _APP_CONSOLE_BITBUCKET_APP_ID
|
||||
- _APP_CONSOLE_BITBUCKET_SECRET
|
||||
- _APP_CONSOLE_GOOGLE_APP_ID
|
||||
@@ -229,6 +230,7 @@ services:
|
||||
- _APP_VCS_GITEA_CLIENT_ID
|
||||
- _APP_VCS_GITEA_CLIENT_SECRET
|
||||
- _APP_VCS_GITEA_WEBHOOK_SECRET
|
||||
- _APP_VCS_GITLAB_ENDPOINT
|
||||
- _APP_VCS_GITLAB_CLIENT_ID
|
||||
- _APP_VCS_GITLAB_CLIENT_SECRET
|
||||
- _APP_VCS_GITLAB_WEBHOOK_SECRET
|
||||
@@ -482,6 +484,7 @@ services:
|
||||
- _APP_VCS_GITEA_CLIENT_ID
|
||||
- _APP_VCS_GITEA_CLIENT_SECRET
|
||||
- _APP_VCS_GITEA_WEBHOOK_SECRET
|
||||
- _APP_VCS_GITLAB_ENDPOINT
|
||||
- _APP_VCS_GITLAB_CLIENT_ID
|
||||
- _APP_VCS_GITLAB_CLIENT_SECRET
|
||||
- _APP_VCS_GITLAB_WEBHOOK_SECRET
|
||||
@@ -824,6 +827,7 @@ services:
|
||||
- _APP_VCS_GITEA_CLIENT_ID
|
||||
- _APP_VCS_GITEA_CLIENT_SECRET
|
||||
- _APP_VCS_GITEA_WEBHOOK_SECRET
|
||||
- _APP_VCS_GITLAB_ENDPOINT
|
||||
- _APP_VCS_GITLAB_CLIENT_ID
|
||||
- _APP_VCS_GITLAB_CLIENT_SECRET
|
||||
- _APP_VCS_GITLAB_WEBHOOK_SECRET
|
||||
|
||||
@@ -11,8 +11,9 @@ use Appwrite\Auth\OAuth2;
|
||||
* Shared with the "Sign in with GitLab" account-login OAuth2 provider, which
|
||||
* stores its secret as JSON ({"clientSecret": "...", "endpoint": "..."}) to
|
||||
* support self-hosted GitLab per-project. The VCS flow (see app/config/vcs.php)
|
||||
* only supports official gitlab.com, but still encodes to that same JSON
|
||||
* shape so getAppSecret()/getEndpoint() stay correct for both consumers.
|
||||
* and the console project (see app/config/console.php) encode to that same JSON
|
||||
* shape, taking their endpoint from _APP_VCS_GITLAB_ENDPOINT and
|
||||
* _APP_CONSOLE_GITLAB_ENDPOINT respectively.
|
||||
*/
|
||||
class Gitlab extends OAuth2
|
||||
{
|
||||
@@ -230,7 +231,8 @@ class Gitlab extends OAuth2
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode the JSON stored in appSecret
|
||||
* Decode the JSON stored in appSecret.
|
||||
* Falls back to treating the raw string as the client secret for backwards compatibility.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -239,8 +241,13 @@ class Gitlab extends OAuth2
|
||||
try {
|
||||
$secret = \json_decode($this->appSecret, true, 512, JSON_THROW_ON_ERROR);
|
||||
} catch (\Throwable $th) {
|
||||
throw new \Exception('Invalid secret');
|
||||
return ['clientSecret' => $this->appSecret];
|
||||
}
|
||||
|
||||
if (!\is_array($secret)) {
|
||||
return ['clientSecret' => $this->appSecret];
|
||||
}
|
||||
|
||||
return $secret;
|
||||
}
|
||||
|
||||
@@ -255,6 +262,6 @@ class Gitlab extends OAuth2
|
||||
$defaultEndpoint = 'https://gitlab.com';
|
||||
$secret = $this->getAppSecret();
|
||||
$endpoint = $secret['endpoint'] ?? $defaultEndpoint;
|
||||
return empty($endpoint) ? $defaultEndpoint : $endpoint;
|
||||
return empty($endpoint) ? $defaultEndpoint : \rtrim($endpoint, '/');
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,7 @@ class Get extends Base
|
||||
System::getEnv('_APP_VCS_GITLAB_CLIENT_ID', ''),
|
||||
\json_encode([
|
||||
'clientSecret' => System::getEnv('_APP_VCS_GITLAB_CLIENT_SECRET', ''),
|
||||
'endpoint' => 'https://gitlab.com',
|
||||
'endpoint' => System::getEnv('_APP_VCS_GITLAB_ENDPOINT', 'https://gitlab.com'),
|
||||
]),
|
||||
$callback,
|
||||
$state,
|
||||
|
||||
@@ -30,7 +30,7 @@ class Get extends Base
|
||||
System::getEnv('_APP_VCS_GITLAB_CLIENT_ID', ''),
|
||||
\json_encode([
|
||||
'clientSecret' => System::getEnv('_APP_VCS_GITLAB_CLIENT_SECRET', ''),
|
||||
'endpoint' => 'https://gitlab.com',
|
||||
'endpoint' => System::getEnv('_APP_VCS_GITLAB_ENDPOINT', 'https://gitlab.com'),
|
||||
]),
|
||||
$callback
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user