diff options
author | Frederic Guillot <fred@kanboard.net> | 2016-01-29 23:59:58 -0500 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2016-01-29 23:59:58 -0500 |
commit | 9b9d823f30f7f7744f412df8ca4c52d7be3c9977 (patch) | |
tree | 50a21284bf17246206c102153ff60a890888d4f2 /app/Auth | |
parent | 04d8c6532c441c4ba4699020374ffab85685082d (diff) |
Move Gitlab and Github authentication to external plugins
Diffstat (limited to 'app/Auth')
-rw-r--r-- | app/Auth/GithubAuth.php | 143 | ||||
-rw-r--r-- | app/Auth/GitlabAuth.php | 143 |
2 files changed, 0 insertions, 286 deletions
diff --git a/app/Auth/GithubAuth.php b/app/Auth/GithubAuth.php deleted file mode 100644 index 83699581..00000000 --- a/app/Auth/GithubAuth.php +++ /dev/null @@ -1,143 +0,0 @@ -<?php - -namespace Kanboard\Auth; - -use Kanboard\Core\Base; -use Kanboard\Core\Security\OAuthAuthenticationProviderInterface; -use Kanboard\User\GithubUserProvider; - -/** - * Github Authentication Provider - * - * @package auth - * @author Frederic Guillot - */ -class GithubAuth extends Base implements OAuthAuthenticationProviderInterface -{ - /** - * User properties - * - * @access protected - * @var \Kanboard\User\GithubUserProvider - */ - protected $userInfo = null; - - /** - * OAuth2 instance - * - * @access protected - * @var \Kanboard\Core\Http\OAuth2 - */ - protected $service; - - /** - * OAuth2 code - * - * @access protected - * @var string - */ - protected $code = ''; - - /** - * Get authentication provider name - * - * @access public - * @return string - */ - public function getName() - { - return 'Github'; - } - - /** - * Authenticate the user - * - * @access public - * @return boolean - */ - public function authenticate() - { - $profile = $this->getProfile(); - - if (! empty($profile)) { - $this->userInfo = new GithubUserProvider($profile); - return true; - } - - return false; - } - - /** - * Set Code - * - * @access public - * @param string $code - * @return GithubAuth - */ - public function setCode($code) - { - $this->code = $code; - return $this; - } - - /** - * Get user object - * - * @access public - * @return GithubUserProvider - */ - public function getUser() - { - return $this->userInfo; - } - - /** - * Get configured OAuth2 service - * - * @access public - * @return \Kanboard\Core\Http\OAuth2 - */ - public function getService() - { - if (empty($this->service)) { - $this->service = $this->oauth->createService( - GITHUB_CLIENT_ID, - GITHUB_CLIENT_SECRET, - $this->helper->url->to('oauth', 'github', array(), '', true), - GITHUB_OAUTH_AUTHORIZE_URL, - GITHUB_OAUTH_TOKEN_URL, - array() - ); - } - - return $this->service; - } - - /** - * Get Github profile - * - * @access public - * @return array - */ - public function getProfile() - { - $this->getService()->getAccessToken($this->code); - - return $this->httpClient->getJson( - GITHUB_API_URL.'user', - array($this->getService()->getAuthorizationHeader()) - ); - } - - /** - * Unlink user - * - * @access public - * @param integer $userId - * @return bool - */ - public function unlink($userId) - { - return $this->user->update(array('id' => $userId, 'github_id' => '')); - } -} diff --git a/app/Auth/GitlabAuth.php b/app/Auth/GitlabAuth.php deleted file mode 100644 index c0a2cf9b..00000000 --- a/app/Auth/GitlabAuth.php +++ /dev/null @@ -1,143 +0,0 @@ -<?php - -namespace Kanboard\Auth; - -use Kanboard\Core\Base; -use Kanboard\Core\Security\OAuthAuthenticationProviderInterface; -use Kanboard\User\GitlabUserProvider; - -/** - * Gitlab Authentication Provider - * - * @package auth - * @author Frederic Guillot - */ -class GitlabAuth extends Base implements OAuthAuthenticationProviderInterface -{ - /** - * User properties - * - * @access private - * @var \Kanboard\User\GitlabUserProvider - */ - private $userInfo = null; - - /** - * OAuth2 instance - * - * @access protected - * @var \Kanboard\Core\Http\OAuth2 - */ - protected $service; - - /** - * OAuth2 code - * - * @access protected - * @var string - */ - protected $code = ''; - - /** - * Get authentication provider name - * - * @access public - * @return string - */ - public function getName() - { - return 'Gitlab'; - } - - /** - * Authenticate the user - * - * @access public - * @return boolean - */ - public function authenticate() - { - $profile = $this->getProfile(); - - if (! empty($profile)) { - $this->userInfo = new GitlabUserProvider($profile); - return true; - } - - return false; - } - - /** - * Set Code - * - * @access public - * @param string $code - * @return GitlabAuth - */ - public function setCode($code) - { - $this->code = $code; - return $this; - } - - /** - * Get user object - * - * @access public - * @return GitlabUserProvider - */ - public function getUser() - { - return $this->userInfo; - } - - /** - * Get configured OAuth2 service - * - * @access public - * @return \Kanboard\Core\Http\OAuth2 - */ - public function getService() - { - if (empty($this->service)) { - $this->service = $this->oauth->createService( - GITLAB_CLIENT_ID, - GITLAB_CLIENT_SECRET, - $this->helper->url->to('oauth', 'gitlab', array(), '', true), - GITLAB_OAUTH_AUTHORIZE_URL, - GITLAB_OAUTH_TOKEN_URL, - array() - ); - } - - return $this->service; - } - - /** - * Get Gitlab profile - * - * @access public - * @return array - */ - public function getProfile() - { - $this->getService()->getAccessToken($this->code); - - return $this->httpClient->getJson( - GITLAB_API_URL.'user', - array($this->getService()->getAuthorizationHeader()) - ); - } - - /** - * Unlink user - * - * @access public - * @param integer $userId - * @return bool - */ - public function unlink($userId) - { - return $this->user->update(array('id' => $userId, 'gitlab_id' => '')); - } -} |