├── .gitignore
├── Template
├── user
│ ├── authentication.php
│ ├── create_remote.php
│ └── external.php
├── auth
│ └── login.php
└── config
│ └── integration.php
├── Makefile
├── Locale
├── cs_CZ
│ └── translations.php
├── da_DK
│ └── translations.php
├── fi_FI
│ └── translations.php
├── ja_JP
│ └── translations.php
├── nb_NO
│ └── translations.php
├── nl_NL
│ └── translations.php
├── pl_PL
│ └── translations.php
├── sv_SE
│ └── translations.php
├── th_TH
│ └── translations.php
├── zh_CN
│ └── translations.php
├── sr_Latn_RS
│ └── translations.php
├── el_GR
│ └── translations.php
├── id_ID
│ └── translations.php
├── my_MY
│ └── translations.php
├── pt_BR
│ └── translations.php
├── pt_PT
│ └── translations.php
├── ru_RU
│ └── translations.php
├── tr_TR
│ └── translations.php
├── de_DE
│ └── translations.php
├── es_ES
│ └── translations.php
├── hu_HU
│ └── translations.php
├── it_IT
│ └── translations.php
├── bs_BA
│ └── translations.php
└── fr_FR
│ └── translations.php
├── Controller
└── OAuthController.php
├── Test
├── PluginTest.php
├── GitlabUserProviderTest.php
└── GitlabAuthProviderTest.php
├── LICENSE
├── Plugin.php
├── User
└── GitlabUserProvider.php
├── README.md
└── Auth
└── GitlabAuthProvider.php
/.gitignore:
--------------------------------------------------------------------------------
1 | *.zip
2 |
--------------------------------------------------------------------------------
/Template/user/authentication.php:
--------------------------------------------------------------------------------
1 | = $this->form->label(t('GitLab Id'), 'gitlab_id') ?>
2 | = $this->form->text('gitlab_id', $values, $errors) ?>
3 |
--------------------------------------------------------------------------------
/Template/user/create_remote.php:
--------------------------------------------------------------------------------
1 | = $this->form->label(t('GitLab Id'), 'gitlab_id') ?>
2 | = $this->form->text('gitlab_id', $values, $errors) ?>
3 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | @ echo "Build archive for plugin ${plugin} version=${version}"
3 | @ git archive HEAD --prefix=${plugin}/ --format=zip -o ${plugin}-${version}.zip
4 |
--------------------------------------------------------------------------------
/Template/auth/login.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | = $this->url->link(t('Login with my GitLab Account'), 'OAuthController', 'handler', array('plugin' => 'GitlabAuth')) ?>
5 |
6 |
7 |
--------------------------------------------------------------------------------
/Locale/cs_CZ/translations.php:
--------------------------------------------------------------------------------
1 | '',
5 | // 'Link my GitLab Account' => '',
6 | // 'Unlink my GitLab Account' => '',
7 | // 'GitLab Account' => '',
8 | // 'GitLab Authentication' => '',
9 | // 'Help on GitLab authentication' => '',
10 | );
11 |
12 |
--------------------------------------------------------------------------------
/Locale/da_DK/translations.php:
--------------------------------------------------------------------------------
1 | '',
5 | // 'Link my GitLab Account' => '',
6 | // 'Unlink my GitLab Account' => '',
7 | // 'GitLab Account' => '',
8 | // 'GitLab Authentication' => '',
9 | // 'Help on GitLab authentication' => '',
10 | );
11 |
12 |
--------------------------------------------------------------------------------
/Locale/fi_FI/translations.php:
--------------------------------------------------------------------------------
1 | '',
5 | // 'Link my GitLab Account' => '',
6 | // 'Unlink my GitLab Account' => '',
7 | // 'GitLab Account' => '',
8 | // 'GitLab Authentication' => '',
9 | // 'Help on GitLab authentication' => '',
10 | );
11 |
12 |
--------------------------------------------------------------------------------
/Locale/ja_JP/translations.php:
--------------------------------------------------------------------------------
1 | '',
5 | // 'Link my GitLab Account' => '',
6 | // 'Unlink my GitLab Account' => '',
7 | // 'GitLab Account' => '',
8 | // 'GitLab Authentication' => '',
9 | // 'Help on GitLab authentication' => '',
10 | );
11 |
12 |
--------------------------------------------------------------------------------
/Locale/nb_NO/translations.php:
--------------------------------------------------------------------------------
1 | '',
5 | // 'Link my GitLab Account' => '',
6 | // 'Unlink my GitLab Account' => '',
7 | // 'GitLab Account' => '',
8 | // 'GitLab Authentication' => '',
9 | // 'Help on GitLab authentication' => '',
10 | );
11 |
12 |
--------------------------------------------------------------------------------
/Locale/nl_NL/translations.php:
--------------------------------------------------------------------------------
1 | '',
5 | // 'Link my GitLab Account' => '',
6 | // 'Unlink my GitLab Account' => '',
7 | // 'GitLab Account' => '',
8 | // 'GitLab Authentication' => '',
9 | // 'Help on GitLab authentication' => '',
10 | );
11 |
12 |
--------------------------------------------------------------------------------
/Locale/pl_PL/translations.php:
--------------------------------------------------------------------------------
1 | '',
5 | // 'Link my GitLab Account' => '',
6 | // 'Unlink my GitLab Account' => '',
7 | // 'GitLab Account' => '',
8 | // 'GitLab Authentication' => '',
9 | // 'Help on GitLab authentication' => '',
10 | );
11 |
12 |
--------------------------------------------------------------------------------
/Locale/sv_SE/translations.php:
--------------------------------------------------------------------------------
1 | '',
5 | // 'Link my GitLab Account' => '',
6 | // 'Unlink my GitLab Account' => '',
7 | // 'GitLab Account' => '',
8 | // 'GitLab Authentication' => '',
9 | // 'Help on GitLab authentication' => '',
10 | );
11 |
12 |
--------------------------------------------------------------------------------
/Locale/th_TH/translations.php:
--------------------------------------------------------------------------------
1 | '',
5 | // 'Link my GitLab Account' => '',
6 | // 'Unlink my GitLab Account' => '',
7 | // 'GitLab Account' => '',
8 | // 'GitLab Authentication' => '',
9 | // 'Help on GitLab authentication' => '',
10 | );
11 |
12 |
--------------------------------------------------------------------------------
/Locale/zh_CN/translations.php:
--------------------------------------------------------------------------------
1 | '',
5 | // 'Link my GitLab Account' => '',
6 | // 'Unlink my GitLab Account' => '',
7 | // 'GitLab Account' => '',
8 | // 'GitLab Authentication' => '',
9 | // 'Help on GitLab authentication' => '',
10 | );
11 |
12 |
--------------------------------------------------------------------------------
/Locale/sr_Latn_RS/translations.php:
--------------------------------------------------------------------------------
1 | '',
5 | // 'Link my GitLab Account' => '',
6 | // 'Unlink my GitLab Account' => '',
7 | // 'GitLab Account' => '',
8 | // 'GitLab Authentication' => '',
9 | // 'Help on GitLab authentication' => '',
10 | );
11 |
12 |
--------------------------------------------------------------------------------
/Locale/el_GR/translations.php:
--------------------------------------------------------------------------------
1 | 'Login with my GitLab Account',
5 | 'Link my GitLab Account' => 'Link my GitLab Account',
6 | 'Unlink my GitLab Account' => 'Unlink my GitLab Account',
7 | 'GitLab Account' => 'GitLab Account',
8 | 'GitLab Authentication' => 'GitLab Authentication',
9 | 'Help on GitLab authentication' => 'Help on GitLab authentication',
10 | );
11 |
12 |
--------------------------------------------------------------------------------
/Locale/id_ID/translations.php:
--------------------------------------------------------------------------------
1 | 'Masuk menggunakan akun GitLab saya',
5 | 'Link my GitLab Account' => 'Hubungkan akun GitLab saya',
6 | 'Unlink my GitLab Account' => 'Putuskan akun GitLab saya',
7 | 'GitLab Account' => 'Akun GitLab',
8 | 'GitLab Authentication' => 'Authentification GitLab',
9 | 'Help on GitLab authentication' => 'Bantuan pada otentifikasi GitLab',
10 | );
11 |
12 |
--------------------------------------------------------------------------------
/Locale/my_MY/translations.php:
--------------------------------------------------------------------------------
1 | 'Masuk menggunakan Akaun GitLab saya',
5 | 'Link my GitLab Account' => 'Hubungkan akaun GitLab saya',
6 | 'Unlink my GitLab Account' => 'Putuskan akaun GitLab saya',
7 | 'GitLab Account' => 'Akaun GitLab',
8 | 'GitLab Authentication' => 'Otentifikasi GitLab',
9 | 'Help on GitLab authentication' => 'Bantuan pada otentifikasi GitLab',
10 | );
11 |
12 |
--------------------------------------------------------------------------------
/Locale/pt_BR/translations.php:
--------------------------------------------------------------------------------
1 | 'Login com a minha conta GitLab',
5 | 'Link my GitLab Account' => 'Vincular minha conta GitLab',
6 | 'Unlink my GitLab Account' => 'Desvincular minha conta GitLab',
7 | 'GitLab Account' => 'Conta GitLab',
8 | 'GitLab Authentication' => 'Autenticação GitLab',
9 | 'Help on GitLab authentication' => 'Ajuda com a autenticação GitLab',
10 | );
11 |
12 |
--------------------------------------------------------------------------------
/Locale/pt_PT/translations.php:
--------------------------------------------------------------------------------
1 | 'Login com a minha Conta GitLab',
5 | 'Link my GitLab Account' => 'Connectar a minha Conta GitLab',
6 | 'Unlink my GitLab Account' => 'Desconectar a minha Conta GitLab',
7 | 'GitLab Account' => 'Conta GitLab',
8 | 'GitLab Authentication' => 'Autenticação GitLab',
9 | 'Help on GitLab authentication' => 'Ajuda com autenticação GitLab',
10 | );
11 |
12 |
--------------------------------------------------------------------------------
/Locale/ru_RU/translations.php:
--------------------------------------------------------------------------------
1 | 'Авторизоваться через аккаунт GitLab',
5 | 'Link my GitLab Account' => 'Привязать аккаунт GitLab',
6 | 'Unlink my GitLab Account' => 'Отвязать аккаунт GitLab',
7 | 'GitLab Account' => 'Аккаунт GitLab',
8 | 'GitLab Authentication' => 'Авторизация через GitLab',
9 | 'Help on GitLab authentication' => 'Помощь а авторизации через GitLab',
10 | );
11 |
12 |
--------------------------------------------------------------------------------
/Locale/tr_TR/translations.php:
--------------------------------------------------------------------------------
1 | 'GitLab hesabımla giriş yap',
5 | 'Link my GitLab Account' => 'GitLab hesabını ilişkilendir',
6 | 'Unlink my GitLab Account' => 'GitLab hesabımla bağlantıyı kopar',
7 | 'GitLab Account' => 'GitLab hesabı',
8 | 'GitLab Authentication' => 'GitLab doğrulaması',
9 | 'Help on GitLab authentication' => 'GitLab doğrulaması hakkında yardım',
10 | );
11 |
12 |
--------------------------------------------------------------------------------
/Locale/de_DE/translations.php:
--------------------------------------------------------------------------------
1 | 'Mit GitLab Account einloggen',
5 | 'Link my GitLab Account' => 'Verknüpfe mein GitLab Account',
6 | 'Unlink my GitLab Account' => 'Trenne meinen GitLab Account',
7 | 'GitLab Account' => 'GitLab Account',
8 | 'GitLab Authentication' => 'GitLab-Authentifizierung',
9 | 'Help on GitLab authentication' => 'Hilfe bei GitLab-Authentifizierung',
10 | );
11 |
12 |
--------------------------------------------------------------------------------
/Locale/es_ES/translations.php:
--------------------------------------------------------------------------------
1 | 'Ingresar usando mi Cuenta en GitLab',
5 | 'Link my GitLab Account' => 'Enlazar con mi Cuenta en GitLab',
6 | 'Unlink my GitLab Account' => 'Desenlazar con mi Cuenta en GitLab',
7 | 'GitLab Account' => 'Cuenta de GitLab',
8 | 'GitLab Authentication' => 'Autenticación GitLab',
9 | 'Help on GitLab authentication' => 'Ayuda con autenticación GitLab',
10 | );
11 |
12 |
--------------------------------------------------------------------------------
/Locale/hu_HU/translations.php:
--------------------------------------------------------------------------------
1 | 'Bejelentkezés a GitLab fiókommal',
5 | 'Link my GitLab Account' => 'Összekapcsolás a GitLab fiókommal',
6 | 'Unlink my GitLab Account' => 'A GitLab fiókom összekapcsolásának megszüntetése',
7 | 'GitLab Account' => 'GitLab fiók',
8 | 'GitLab Authentication' => 'GitLab hitelesítés',
9 | 'Help on GitLab authentication' => 'Súgó a GitLab hitelesítéshez',
10 | );
11 |
12 |
--------------------------------------------------------------------------------
/Locale/it_IT/translations.php:
--------------------------------------------------------------------------------
1 | 'Accedi tramite il mio account GitLab',
5 | 'Link my GitLab Account' => 'Collega il mio Account GitLab',
6 | 'Unlink my GitLab Account' => 'Scollega il mio Account GitLab',
7 | 'GitLab Account' => 'Account GitLab',
8 | 'GitLab Authentication' => 'Autenticazione con GitLab',
9 | 'Help on GitLab authentication' => 'Aiuto sull\'autenticazione con GitLab',
10 | );
11 |
12 |
--------------------------------------------------------------------------------
/Locale/bs_BA/translations.php:
--------------------------------------------------------------------------------
1 | 'Prijava s mojim GitLab korisničkim računom',
5 | 'Link my GitLab Account' => 'Veza s mojim GitLab korisničkim računom',
6 | 'Unlink my GitLab Account' => 'Prekini vezu s mojim GitLab korisničkim računom',
7 | 'GitLab Account' => 'GitLab korisnički račun',
8 | 'GitLab Authentication' => 'GitLab autentifikacija',
9 | 'Help on GitLab authentication' => 'Pomoć na GitLab autentifikacija',
10 | );
11 |
12 |
--------------------------------------------------------------------------------
/Controller/OAuthController.php:
--------------------------------------------------------------------------------
1 | step1('Gitlab');
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Test/PluginTest.php:
--------------------------------------------------------------------------------
1 | container);
12 | $this->assertSame(null, $plugin->initialize());
13 | $this->assertSame(null, $plugin->onStartup());
14 | $this->assertNotEmpty($plugin->getPluginName());
15 | $this->assertNotEmpty($plugin->getPluginDescription());
16 | $this->assertNotEmpty($plugin->getPluginAuthor());
17 | $this->assertNotEmpty($plugin->getPluginVersion());
18 | $this->assertNotEmpty($plugin->getPluginHomepage());
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Template/user/external.php:
--------------------------------------------------------------------------------
1 | = t('GitLab Account') ?>
2 |
3 |
4 | user->isCurrentUser($user['id'])): ?>
5 |
6 | = $this->url->link(t('Link my GitLab Account'), 'OAuthController', 'handler', array('plugin' => 'GitlabAuth'), true) ?>
7 |
8 | = $this->url->link(t('Unlink my GitLab Account'), 'OAuthController', 'unlink', array('backend' => 'Gitlab'), true) ?>
9 |
10 |
11 | = empty($user['gitlab_id']) ? t('No account linked.') : t('Account linked.') ?>
12 |
13 |
14 |
--------------------------------------------------------------------------------
/Locale/fr_FR/translations.php:
--------------------------------------------------------------------------------
1 | 'Se connecter avec mon compte GitLab',
5 | 'Link my GitLab Account' => 'Lier mon compte GitLab',
6 | 'Unlink my GitLab Account' => 'Ne plus utiliser mon compte GitLab',
7 | 'GitLab Account' => 'Compte GitLab',
8 | 'GitLab Authentication' => 'Authentification GitLab',
9 | 'Help on GitLab authentication' => 'Aide sur l\'authentification GitLab',
10 | 'Leave blank to use the default URL.' => 'Laissez vide pour utiliser l\'URL par défaut.',
11 | 'Allow Account Creation' => 'Autoriser la création de comptes',
12 | 'Allow account creation only for those domains' => 'Autoriser la création de compte seulement pour ces noms de domaines',
13 | 'Use a comma to enter multiple domains: domain1.tld, domain2.tld' => 'Utilisez une virgule pour mettre plusieurs nom de domaines : domaine1.tld, domaine2.tld',
14 | );
15 |
16 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 Frédéric Guillot
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Plugin.php:
--------------------------------------------------------------------------------
1 | authenticationManager->register(new GitlabAuthProvider($this->container));
15 | $this->applicationAccessMap->add('OAuthController', 'handler', Role::APP_PUBLIC);
16 |
17 | $this->route->addRoute('/oauth/gitlab', 'OAuthController', 'handler', 'GitlabAuth');
18 |
19 | $this->template->hook->attach('template:auth:login-form:after', 'GitlabAuth:auth/login');
20 | $this->template->hook->attach('template:config:integrations', 'GitlabAuth:config/integration');
21 | $this->template->hook->attach('template:user:external', 'GitlabAuth:user/external');
22 | $this->template->hook->attach('template:user:authentication:form', 'GitlabAuth:user/authentication');
23 | $this->template->hook->attach('template:user:create-remote:form', 'GitlabAuth:user/create_remote');
24 | }
25 |
26 | public function onStartup()
27 | {
28 | Translator::load($this->languageModel->getCurrentLanguage(), __DIR__.'/Locale');
29 | }
30 |
31 | public function getPluginName()
32 | {
33 | return 'GitLab Authentication';
34 | }
35 |
36 | public function getPluginDescription()
37 | {
38 | return t('Use GitLab as authentication provider');
39 | }
40 |
41 | public function getPluginAuthor()
42 | {
43 | return 'Frédéric Guillot';
44 | }
45 |
46 | public function getPluginVersion()
47 | {
48 | return '1.0.5';
49 | }
50 |
51 | public function getPluginHomepage()
52 | {
53 | return 'https://github.com/kanboard/plugin-gitlab-auth';
54 | }
55 |
56 | public function getCompatibleVersion()
57 | {
58 | return '>=1.0.37';
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/User/GitlabUserProvider.php:
--------------------------------------------------------------------------------
1 | user = $user;
30 | $this->allowUserCreation = $allowUserCreation;
31 | }
32 |
33 | /**
34 | * Return true to allow automatic user creation
35 | *
36 | * @access public
37 | * @return boolean
38 | */
39 | public function isUserCreationAllowed()
40 | {
41 | return $this->allowUserCreation;
42 | }
43 |
44 | /**
45 | * Get username
46 | *
47 | * @access public
48 | * @return string
49 | */
50 | public function getUsername()
51 | {
52 | if ($this->allowUserCreation) {
53 | return $this->user['username'];
54 | }
55 |
56 | return '';
57 | }
58 |
59 | /**
60 | * Get external id column name
61 | *
62 | * @access public
63 | * @return string
64 | */
65 | public function getExternalIdColumn()
66 | {
67 | return 'gitlab_id';
68 | }
69 |
70 | /**
71 | * Get extra user attributes
72 | *
73 | * @access public
74 | * @return array
75 | */
76 | public function getExtraAttributes()
77 | {
78 | if ($this->allowUserCreation) {
79 | return array(
80 | 'is_ldap_user' => 1,
81 | 'disable_login_form' => 1,
82 | );
83 | }
84 |
85 | return array();
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/Template/config/integration.php:
--------------------------------------------------------------------------------
1 | = t('Gitlab Authentication') ?>
2 |
3 |
4 | = $this->form->label(t('GitLab OAuth callback URL'), 'gitlab_oauth_url') ?>
5 |
6 |
7 | = $this->form->label(t('GitLab Client Id'), 'gitlab_client_id') ?>
8 | = $this->form->text('gitlab_client_id', $values) ?>
9 |
10 | = $this->form->label(t('GitLab Client Secret'), 'gitlab_client_secret') ?>
11 | = $this->form->password('gitlab_client_secret', $values) ?>
12 |
13 | = $this->form->label(t('GitLab Authorize URL'), 'gitlab_authorize_url') ?>
14 | = $this->form->text('gitlab_authorize_url', $values) ?>
15 |
= t('Leave blank to use the default URL.') ?>
16 |
17 | = $this->form->label(t('GitLab Token URL'), 'gitlab_token_url') ?>
18 | = $this->form->text('gitlab_token_url', $values) ?>
19 |
20 | = $this->form->label(t('GitLab API URL'), 'gitlab_api_url') ?>
21 | = $this->form->text('gitlab_api_url', $values) ?>
22 |
23 | = $this->form->hidden('gitlab_account_creation', array('gitlab_account_creation' => 0)) ?>
24 | = $this->form->checkbox('gitlab_account_creation', t('Allow Account Creation'), 1, isset($values['gitlab_account_creation']) && $values['gitlab_account_creation'] == 1) ?>
25 |
26 | = $this->form->label(t('Allow account creation only for those domains'), 'gitlab_email_domains') ?>
27 | = $this->form->text('gitlab_email_domains', $values) ?>
28 |
= t('Use a comma to enter multiple domains: domain1.tld, domain2.tld') ?>
29 |
30 |
= t('Help on GitLab authentication') ?>
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/Test/GitlabUserProviderTest.php:
--------------------------------------------------------------------------------
1 | assertFalse($userProvider->isUserCreationAllowed());
13 |
14 | $userProvider = new GitlabUserProvider(array(), true);
15 | $this->assertTrue($userProvider->isUserCreationAllowed());
16 | }
17 |
18 | public function testGetEmail()
19 | {
20 | $userProvider = new GitlabUserProvider(array('email' => 'test@gmail.com'));
21 | $this->assertEquals('test@gmail.com', $userProvider->getEmail());
22 | }
23 |
24 | public function testGetRole()
25 | {
26 | $userProvider = new GitlabUserProvider(array('email' => 'test@gmail.com'), true);
27 | $this->assertSame('', $userProvider->getRole());
28 | }
29 |
30 | public function testGetName()
31 | {
32 | $userProvider = new GitlabUserProvider(array());
33 | $this->assertEquals('', $userProvider->getName());
34 |
35 | $userProvider = new GitlabUserProvider(array('name' => 'test'));
36 | $this->assertEquals('test', $userProvider->getName());
37 | }
38 |
39 | public function testGetUserName()
40 | {
41 | $userProvider = new GitlabUserProvider(array('username' => 'test'));
42 | $this->assertEquals('', $userProvider->getUsername());
43 |
44 | $userProvider = new GitlabUserProvider(array('username' => 'test'), true);
45 | $this->assertEquals('test', $userProvider->getUsername());
46 | }
47 |
48 | public function testGetExternalIdColumn()
49 | {
50 | $userProvider = new GitlabUserProvider(array('email' => 'test@gmail.com'));
51 | $this->assertEquals('gitlab_id', $userProvider->getExternalIdColumn());
52 | }
53 |
54 | public function testGetExtraAttribute()
55 | {
56 | $userProvider = new GitlabUserProvider(array('email' => 'test@gmail.com'));
57 | $this->assertSame(array(), $userProvider->getExtraAttributes());
58 |
59 | $userProvider = new GitlabUserProvider(array('email' => 'test@gmail.com'), true);
60 | $this->assertSame(array('is_ldap_user' => 1, 'disable_login_form' => 1), $userProvider->getExtraAttributes());
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | GitLab Authentication
2 | =====================
3 |
4 | Link a GitLab account to a Kanboard user profile.
5 |
6 | Author
7 | ------
8 |
9 | - Frédéric Guillot
10 | - License MIT
11 |
12 | Requirements
13 | ------------
14 |
15 | - Kanboard >= 1.0.37
16 | - Account on [GitLab.com](https://gitlab.com) or you own self-hosted GitLab instance
17 | - Have Kanboard registered as application in GitLab (**Settings > Applications**)
18 | - Kanboard application URL is defined properly
19 |
20 | Installation
21 | ------------
22 |
23 | You have the choice between 3 methods:
24 |
25 | 1. Install the plugin from the Kanboard plugin manager in one click
26 | 2. Download the zip file and decompress everything under the directory `plugins/GitlabAuth`
27 | 3. Clone this repository into the folder `plugins/GitlabAuth`
28 |
29 | Note: Plugin folder is case-sensitive.
30 |
31 | Documentation
32 | -------------
33 |
34 | ### How does this work?
35 |
36 | The GitLab authentication in Kanboard uses the [OAuth 2.0](http://oauth.net/2/) protocol, so any user of Kanboard can be linked to a GitLab account.
37 |
38 | That means you can use your GitLab account to login on Kanboard.
39 |
40 | ### Installation instructions
41 |
42 | #### Setting up OAuth 2.0
43 |
44 | - On GitLab, register a new application by following the [official documentation](http://doc.gitlab.com/ce/integration/oauth_provider.html)
45 | - In Kanboard, you can get the **callback url** in **Settings > Integrations > GitLab Authentication**, just copy and paste the url
46 |
47 | #### Setting up Kanboard
48 |
49 | 
50 |
51 | 1. The easiest way is to copy and paste the GitLab OAuth2 credentials in the form **Settings > Integrations > GitLab Authentication**.
52 | 2. Or add the credentials in your custom config file
53 |
54 | If you use the second method, use these parameters in your `config.php`:
55 |
56 | ```php
57 | // GitLab application id
58 | define('GITLAB_CLIENT_ID', 'YOUR_APPLICATION_ID');
59 |
60 | // GitLab application secret
61 | define('GITLAB_CLIENT_SECRET', 'YOUR_APPLICATION_SECRET');
62 | ```
63 |
64 | #### Custom endpoints for self-hosted GitLab
65 |
66 | Change the default values if you use a self-hosted instance of GitLab:
67 |
68 | - GitLab Authorize URL: `http://YOUR_GITLAB_HOSTNAME:CUSTOM_PORT/oauth/authorize` (example: `http://192.168.99.100:8080/oauth/authorize`)
69 | - GitLab Token URL: `http://YOUR_GITLAB_HOSTNAME:CUSTOM_PORT/oauth/token`
70 | - GitLab API URL: `http://YOUR_GITLAB_HOSTNAME:CUSTOM_PORT/api/v3/` (don't forget the trailing slash)
71 |
72 |
73 | ### How to link an existing GitLab account
74 |
75 | 
76 |
77 | 1. Go to your user profile
78 | 2. Click on **External accounts**
79 | 3. Click on the link **Link my GitLab Account**
80 | 4. You are redirected to the **GitLab authorization form**
81 | 5. Authorize Kanboard by clicking on the button **Accept**
82 | 6. Your account is now linked
83 |
84 | Now, on the login page you can be authenticated in one click with the link **Login with my GitLab Account**.
85 |
86 | Your name and email are automatically updated from your GitLab Account if defined.
87 |
88 |
89 | ### How to create automatically users during the first login
90 |
91 | 
92 |
93 | 1. On the settings page, check the box **Allow Account Creation**
94 | 2. If you would like to apply a restriction based on the email domain name enter the correct value in the second field
95 |
96 | New users will have the same username as the one in GitLab and they will be tagged as remote user.
97 |
98 | **Important Note**: If you use the public GitLab and don't apply any domain restriction, everybody in the world will be able to sign in.
99 |
100 |
101 | ### Notes
102 |
103 | Kanboard uses these information from your GitLab profile:
104 |
105 | - Username
106 | - Full name
107 | - Email address
108 | - GitLab unique id
109 |
110 | The GitLab unique id is used to link the local user account and the GitLab account.
111 |
112 | ### Known issues
113 |
114 | GitLab OAuth will work only with url rewrite enabled.
115 | At the moment, GitLab doesn't support callback url with query string parameters. See [GitLab issue](https://gitlab.com/gitlab-org/gitlab-ce/issues/2443).
116 |
--------------------------------------------------------------------------------
/Auth/GitlabAuthProvider.php:
--------------------------------------------------------------------------------
1 | getProfile();
61 |
62 | if (! empty($profile)) {
63 | $this->userInfo = new GitlabUserProvider($profile, $this->isAccountCreationAllowed($profile));
64 | return true;
65 | }
66 |
67 | return false;
68 | }
69 |
70 | /**
71 | * Set Code
72 | *
73 | * @access public
74 | * @param string $code
75 | * @return $this
76 | */
77 | public function setCode($code)
78 | {
79 | $this->code = $code;
80 | return $this;
81 | }
82 |
83 | /**
84 | * Get user object
85 | *
86 | * @access public
87 | * @return GitlabUserProvider
88 | */
89 | public function getUser()
90 | {
91 | return $this->userInfo;
92 | }
93 |
94 | /**
95 | * Get configured OAuth2 service
96 | *
97 | * @access public
98 | * @return \Kanboard\Core\Http\OAuth2
99 | */
100 | public function getService()
101 | {
102 | if (empty($this->service)) {
103 | $this->service = $this->oauth->createService(
104 | $this->getClientId(),
105 | $this->getClientSecret(),
106 | $this->helper->url->to('OAuthController', 'handler', array('plugin' => 'GitlabAuth'), '', true),
107 | $this->getOAuthAuthorizeUrl(),
108 | $this->getOAuthTokenUrl(),
109 | array()
110 | );
111 | }
112 |
113 | return $this->service;
114 | }
115 |
116 | /**
117 | * Get Gitlab profile
118 | *
119 | * @access public
120 | * @return array
121 | */
122 | public function getProfile()
123 | {
124 | $this->getService()->getAccessToken($this->code);
125 |
126 | return $this->httpClient->getJson(
127 | $this->getApiUrl().'user',
128 | array($this->getService()->getAuthorizationHeader())
129 | );
130 | }
131 |
132 | /**
133 | * Unlink user
134 | *
135 | * @access public
136 | * @param integer $userId
137 | * @return bool
138 | */
139 | public function unlink($userId)
140 | {
141 | return $this->userModel->update(array('id' => $userId, 'gitlab_id' => ''));
142 | }
143 |
144 | /**
145 | * Get client id
146 | *
147 | * @access public
148 | * @return string
149 | */
150 | public function getClientId()
151 | {
152 | if (defined('GITLAB_CLIENT_ID') && GITLAB_CLIENT_ID) {
153 | return GITLAB_CLIENT_ID;
154 | }
155 |
156 | return $this->configModel->get('gitlab_client_id');
157 | }
158 |
159 | /**
160 | * Get client secret
161 | *
162 | * @access public
163 | * @return string
164 | */
165 | public function getClientSecret()
166 | {
167 | if (defined('GITLAB_CLIENT_SECRET') && GITLAB_CLIENT_SECRET) {
168 | return GITLAB_CLIENT_SECRET;
169 | }
170 |
171 | return $this->configModel->get('gitlab_client_secret');
172 | }
173 |
174 | /**
175 | * Get authorize url
176 | *
177 | * @access public
178 | * @return string
179 | */
180 | public function getOAuthAuthorizeUrl()
181 | {
182 | if (defined('GITLAB_OAUTH_AUTHORIZE_URL') && GITLAB_OAUTH_AUTHORIZE_URL) {
183 | return GITLAB_OAUTH_AUTHORIZE_URL;
184 | }
185 |
186 | return $this->configModel->get('gitlab_authorize_url', 'https://gitlab.com/oauth/authorize');
187 | }
188 |
189 | /**
190 | * Get token url
191 | *
192 | * @access public
193 | * @return string
194 | */
195 | public function getOAuthTokenUrl()
196 | {
197 | if (defined('GITLAB_OAUTH_TOKEN_URL') && GITLAB_OAUTH_TOKEN_URL) {
198 | return GITLAB_OAUTH_TOKEN_URL;
199 | }
200 |
201 | return $this->configModel->get('gitlab_token_url', 'https://gitlab.com/oauth/token');
202 | }
203 |
204 | /**
205 | * Get API url
206 | *
207 | * @access public
208 | * @return string
209 | */
210 | public function getApiUrl()
211 | {
212 | if (defined('GITLAB_API_URL') && GITLAB_API_URL) {
213 | return GITLAB_API_URL;
214 | }
215 |
216 | return $this->configModel->get('gitlab_api_url', 'https://gitlab.com/api/v3/');
217 | }
218 |
219 | /**
220 | * Return true if the account creation is allowed according to the settings
221 | *
222 | * @access public
223 | * @param array $profile
224 | * @return bool
225 | */
226 | public function isAccountCreationAllowed(array $profile)
227 | {
228 | if ($this->configModel->get('gitlab_account_creation', 0) == 1) {
229 | $domains = $this->configModel->get('gitlab_email_domains');
230 |
231 | if (! empty($domains)) {
232 | return $this->validateDomainRestriction($profile, $domains);
233 | }
234 |
235 | return true;
236 | }
237 |
238 | return false;
239 | }
240 |
241 | /**
242 | * Validate domain restriction
243 | *
244 | * @access private
245 | * @param array $profile
246 | * @param string $domains
247 | * @return bool
248 | */
249 | public function validateDomainRestriction(array $profile, $domains)
250 | {
251 | foreach (explode(',', $domains) as $domain) {
252 | $domain = trim($domain);
253 |
254 | if (strpos($profile['email'], $domain) > 0) {
255 | return true;
256 | }
257 | }
258 |
259 | return false;
260 | }
261 | }
262 |
--------------------------------------------------------------------------------
/Test/GitlabAuthProviderTest.php:
--------------------------------------------------------------------------------
1 | container);
13 | $this->assertEquals('Gitlab', $provider->getName());
14 | }
15 |
16 | public function testGetClientId()
17 | {
18 | $provider = new GitlabAuthProvider($this->container);
19 | $this->assertEmpty($provider->getClientId());
20 |
21 | $this->assertTrue($this->container['configModel']->save(array('gitlab_client_id' => 'my_id')));
22 | $this->container['memoryCache']->flush();
23 |
24 | $this->assertEquals('my_id', $provider->getClientId());
25 | }
26 |
27 | public function testGetClientSecret()
28 | {
29 | $provider = new GitlabAuthProvider($this->container);
30 | $this->assertEmpty($provider->getClientSecret());
31 |
32 | $this->assertTrue($this->container['configModel']->save(array('gitlab_client_secret' => 'secret')));
33 | $this->container['memoryCache']->flush();
34 |
35 | $this->assertEquals('secret', $provider->getClientSecret());
36 | }
37 |
38 | public function testGetOAuthAuthorizeUrl()
39 | {
40 | $provider = new GitlabAuthProvider($this->container);
41 | $this->assertEquals('https://gitlab.com/oauth/authorize', $provider->getOAuthAuthorizeUrl());
42 |
43 | $this->assertTrue($this->container['configModel']->save(array('gitlab_authorize_url' => 'my auth url')));
44 | $this->container['memoryCache']->flush();
45 |
46 | $this->assertEquals('my auth url', $provider->getOAuthAuthorizeUrl());
47 | }
48 |
49 | public function testGetOAuthTokenUrl()
50 | {
51 | $provider = new GitlabAuthProvider($this->container);
52 | $this->assertEquals('https://gitlab.com/oauth/token', $provider->getOAuthTokenUrl());
53 |
54 | $this->assertTrue($this->container['configModel']->save(array('gitlab_token_url' => 'my token url')));
55 | $this->container['memoryCache']->flush();
56 |
57 | $this->assertEquals('my token url', $provider->getOAuthTokenUrl());
58 | }
59 |
60 | public function testGetApiUrl()
61 | {
62 | $provider = new GitlabAuthProvider($this->container);
63 | $this->assertEquals('https://gitlab.com/api/v3/', $provider->getApiUrl());
64 |
65 | $this->assertTrue($this->container['configModel']->save(array('gitlab_api_url' => 'my api url')));
66 | $this->container['memoryCache']->flush();
67 |
68 | $this->assertEquals('my api url', $provider->getApiUrl());
69 | }
70 |
71 | public function testAuthenticationSuccessful()
72 | {
73 | $profile = array(
74 | 'id' => 1234,
75 | 'email' => 'test@localhost',
76 | 'name' => 'Test',
77 | );
78 |
79 | $provider = $this
80 | ->getMockBuilder('\Kanboard\Plugin\GitlabAuth\Auth\GitlabAuthProvider')
81 | ->setConstructorArgs(array($this->container))
82 | ->setMethods(array(
83 | 'getProfile',
84 | ))
85 | ->getMock();
86 |
87 | $provider->expects($this->once())
88 | ->method('getProfile')
89 | ->will($this->returnValue($profile));
90 |
91 | $this->assertInstanceOf('Kanboard\Plugin\GitlabAuth\Auth\GitlabAuthProvider', $provider->setCode('1234'));
92 |
93 | $this->assertTrue($provider->authenticate());
94 |
95 | $user = $provider->getUser();
96 | $this->assertInstanceOf('Kanboard\Plugin\GitlabAuth\User\GitlabUserProvider', $user);
97 | $this->assertEquals('Test', $user->getName());
98 | $this->assertEquals('', $user->getInternalId());
99 | $this->assertEquals(1234, $user->getExternalId());
100 | $this->assertEquals('', $user->getRole());
101 | $this->assertEquals('', $user->getUsername());
102 | $this->assertEquals('test@localhost', $user->getEmail());
103 | $this->assertEquals('gitlab_id', $user->getExternalIdColumn());
104 | $this->assertEquals(array(), $user->getExternalGroupIds());
105 | $this->assertEquals(array(), $user->getExtraAttributes());
106 | $this->assertFalse($user->isUserCreationAllowed());
107 | }
108 |
109 | public function testAuthenticationFailed()
110 | {
111 | $provider = $this
112 | ->getMockBuilder('\Kanboard\Plugin\GitlabAuth\Auth\GitlabAuthProvider')
113 | ->setConstructorArgs(array($this->container))
114 | ->setMethods(array(
115 | 'getProfile',
116 | ))
117 | ->getMock();
118 |
119 | $provider->expects($this->once())
120 | ->method('getProfile')
121 | ->will($this->returnValue(array()));
122 |
123 | $this->assertFalse($provider->authenticate());
124 | $this->assertEquals(null, $provider->getUser());
125 | }
126 |
127 | public function testGetService()
128 | {
129 | $provider = new GitlabAuthProvider($this->container);
130 | $this->assertInstanceOf('Kanboard\Core\Http\OAuth2', $provider->getService());
131 | }
132 |
133 | public function testUnlink()
134 | {
135 | $userModel = new UserModel($this->container);
136 | $provider = new GitlabAuthProvider($this->container);
137 |
138 | $this->assertEquals(2, $userModel->create(array('username' => 'test', 'gitlab_id' => '1234')));
139 | $this->assertNotEmpty($userModel->getByExternalId('gitlab_id', 1234));
140 |
141 | $this->assertTrue($provider->unlink(2));
142 | $this->assertEmpty($userModel->getByExternalId('gitlab_id', 1234));
143 | }
144 |
145 | public function testIsAccountCreationAllowed()
146 | {
147 | $provider = new GitlabAuthProvider($this->container);
148 | $this->assertFalse($provider->isAccountCreationAllowed(array()));
149 |
150 | $this->assertTrue($this->container['configModel']->save(array('gitlab_account_creation' => '0')));
151 | $this->container['memoryCache']->flush();
152 | $this->assertFalse($provider->isAccountCreationAllowed(array()));
153 |
154 | $this->assertTrue($this->container['configModel']->save(array('gitlab_account_creation' => '1')));
155 | $this->container['memoryCache']->flush();
156 | $this->assertTrue($provider->isAccountCreationAllowed(array()));
157 | }
158 |
159 | public function testEmailRestrictions()
160 | {
161 | $provider = new GitlabAuthProvider($this->container);
162 |
163 | $this->assertTrue($this->container['configModel']->save(array('gitlab_account_creation' => '0', 'gitlab_email_domains' => 'mydomain.tld')));
164 | $this->container['memoryCache']->flush();
165 | $this->assertFalse($provider->isAccountCreationAllowed(array('email' => 'me@mydomain.tld')));
166 |
167 | $this->assertTrue($this->container['configModel']->save(array('gitlab_account_creation' => '1', 'gitlab_email_domains' => 'mydomain.tld')));
168 | $this->container['memoryCache']->flush();
169 | $this->assertTrue($provider->isAccountCreationAllowed(array('email' => 'me@mydomain.tld')));
170 | $this->assertFalse($provider->isAccountCreationAllowed(array('email' => 'me@my-other-domain.tld')));
171 | }
172 | }
173 |
--------------------------------------------------------------------------------