diff --git a/app/config/providers.php b/app/config/providers.php index 7dc70c92fd..9e5f329ebb 100644 --- a/app/config/providers.php +++ b/app/config/providers.php @@ -19,12 +19,12 @@ return [ 'gitlab' => [ 'developers' => 'https://docs.gitlab.com/ee/api/', 'icon' => 'icon-gitlab', - 'enabled' => false, + 'enabled' => true, ], 'google' => [ 'developers' => 'https://developers.google.com/', 'icon' => 'icon-google', - 'enabled' => false, + 'enabled' => true, ], 'instagram' => [ 'developers' => 'https://www.instagram.com/developer/', diff --git a/docker-compose.yml b/docker-compose.yml index 2cd1d9bb4d..c45a3294f7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,12 +16,12 @@ services: - "80:80" - "443:443" depends_on: - - mariadb - - redis - - smtp - - clamav - - influxdb - - telegraf + - mariadb + - redis + - smtp + - clamav + - influxdb + - telegraf environment: - _APP_ENV=development - _APP_OPENSSL_KEY_V1=your-secret-key diff --git a/docs/AddOAuthProvider.md b/docs/AddOAuthProvider.md index d35278d879..b25e25195b 100644 --- a/docs/AddOAuthProvider.md +++ b/docs/AddOAuthProvider.md @@ -30,8 +30,8 @@ Once finished setting all the metadata for the new provider you need to start co Create a new class that extends the basic OAuth provider abstract class in this location: -``` -\Auth\OAuth\ProviderName +```bash +src/Auth/OAuth/ProviderName ``` Note that the class name should start with a capital letter as PHP FIG standards suggest. diff --git a/public/images/oauth/gitlab.png b/public/images/oauth/gitlab.png new file mode 100644 index 0000000000..35cb5e9dab Binary files /dev/null and b/public/images/oauth/gitlab.png differ diff --git a/public/images/oauth/google.png b/public/images/oauth/google.png new file mode 100644 index 0000000000..bcd5be41ed Binary files /dev/null and b/public/images/oauth/google.png differ diff --git a/src/Auth/OAuth/Gitlab.php b/src/Auth/OAuth/Gitlab.php new file mode 100644 index 0000000000..0f2da4ac9b --- /dev/null +++ b/src/Auth/OAuth/Gitlab.php @@ -0,0 +1,121 @@ +version.'/dialog/oauth?client_id='.urlencode($this->appID).'&redirect_uri='.urlencode($this->callback).'&scope=email&state='.urlencode(json_encode($this->state)); + } + + /** + * @param string $code + * + * @return string + */ + public function getAccessToken(string $code):string + { + $accessToken = $this->request('GET', 'https://graph.google.com/'.$this->version.'/oauth/access_token?'. + 'client_id='.urlencode($this->appID). + '&redirect_uri='.urlencode($this->callback). + '&client_secret='.urlencode($this->appSecret). + '&code='.urlencode($code) + ); + + $accessToken = json_decode($accessToken, true); // + + if (isset($accessToken['access_token'])) { + return $accessToken['access_token']; + } + + return ''; + } + + /** + * @param string $accessToken + * + * @return string + */ + public function getUserID(string $accessToken):string + { + $user = $this->getUser($accessToken); + + if (isset($user['id'])) { + return $user['id']; + } + + return ''; + } + + /** + * @param string $accessToken + * + * @return string + */ + public function getUserEmail(string $accessToken):string + { + $user = $this->getUser($accessToken); + + if (isset($user['email'])) { + return $user['email']; + } + + return ''; + } + + /** + * @param string $accessToken + * + * @return string + */ + public function getUserName(string $accessToken):string + { + $user = $this->getUser($accessToken); + + if (isset($user['name'])) { + return $user['name']; + } + + return ''; + } + + /** + * @param string $accessToken + * + * @return array + */ + protected function getUser(string $accessToken):array + { + if (empty($this->user)) { + $user = $this->request('GET', 'https://graph.google.com/'.$this->version.'/me?fields=email,name&access_token='.urlencode($accessToken)); + + $this->user = json_decode($user, true); + } + + return $this->user; + } +} diff --git a/src/Auth/OAuth/Google.php b/src/Auth/OAuth/Google.php new file mode 100644 index 0000000000..de4cd546ae --- /dev/null +++ b/src/Auth/OAuth/Google.php @@ -0,0 +1,121 @@ +version.'/dialog/oauth?client_id='.urlencode($this->appID).'&redirect_uri='.urlencode($this->callback).'&scope=email&state='.urlencode(json_encode($this->state)); + } + + /** + * @param string $code + * + * @return string + */ + public function getAccessToken(string $code):string + { + $accessToken = $this->request('GET', 'https://graph.google.com/'.$this->version.'/oauth/access_token?'. + 'client_id='.urlencode($this->appID). + '&redirect_uri='.urlencode($this->callback). + '&client_secret='.urlencode($this->appSecret). + '&code='.urlencode($code) + ); + + $accessToken = json_decode($accessToken, true); // + + if (isset($accessToken['access_token'])) { + return $accessToken['access_token']; + } + + return ''; + } + + /** + * @param string $accessToken + * + * @return string + */ + public function getUserID(string $accessToken):string + { + $user = $this->getUser($accessToken); + + if (isset($user['id'])) { + return $user['id']; + } + + return ''; + } + + /** + * @param string $accessToken + * + * @return string + */ + public function getUserEmail(string $accessToken):string + { + $user = $this->getUser($accessToken); + + if (isset($user['email'])) { + return $user['email']; + } + + return ''; + } + + /** + * @param string $accessToken + * + * @return string + */ + public function getUserName(string $accessToken):string + { + $user = $this->getUser($accessToken); + + if (isset($user['name'])) { + return $user['name']; + } + + return ''; + } + + /** + * @param string $accessToken + * + * @return array + */ + protected function getUser(string $accessToken):array + { + if (empty($this->user)) { + $user = $this->request('GET', 'https://graph.google.com/'.$this->version.'/me?fields=email,name&access_token='.urlencode($accessToken)); + + $this->user = json_decode($user, true); + } + + return $this->user; + } +}