2011-02-21 07:47:56 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2012-02-03 02:25:31 +01:00
|
|
|
* Copyright 2012 Facebook, Inc.
|
2011-02-21 07:47:56 +01:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2012-03-13 19:18:11 +01:00
|
|
|
final class PhabricatorOAuthProviderGitHub extends PhabricatorOAuthProvider {
|
2011-02-21 07:47:56 +01:00
|
|
|
|
2011-02-28 04:47:22 +01:00
|
|
|
private $userData;
|
|
|
|
|
2011-02-21 07:47:56 +01:00
|
|
|
public function getProviderKey() {
|
|
|
|
return self::PROVIDER_GITHUB;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getProviderName() {
|
2012-02-03 02:25:31 +01:00
|
|
|
return 'GitHub';
|
2011-02-21 07:47:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function isProviderEnabled() {
|
|
|
|
return PhabricatorEnv::getEnvConfig('github.auth-enabled');
|
|
|
|
}
|
|
|
|
|
2011-02-28 04:47:22 +01:00
|
|
|
public function isProviderLinkPermanent() {
|
|
|
|
return PhabricatorEnv::getEnvConfig('github.auth-permanent');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isProviderRegistrationEnabled() {
|
|
|
|
return PhabricatorEnv::getEnvConfig('github.registration-enabled');
|
|
|
|
}
|
|
|
|
|
2011-02-21 07:47:56 +01:00
|
|
|
public function getClientID() {
|
|
|
|
return PhabricatorEnv::getEnvConfig('github.application-id');
|
|
|
|
}
|
|
|
|
|
2012-02-17 18:55:16 +01:00
|
|
|
public function renderGetClientIDHelp() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2011-02-21 07:47:56 +01:00
|
|
|
public function getClientSecret() {
|
|
|
|
return PhabricatorEnv::getEnvConfig('github.application-secret');
|
|
|
|
}
|
|
|
|
|
2012-02-17 18:55:16 +01:00
|
|
|
public function renderGetClientSecretHelp() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2011-02-21 07:47:56 +01:00
|
|
|
public function getAuthURI() {
|
|
|
|
return 'https://github.com/login/oauth/authorize';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getTokenURI() {
|
|
|
|
return 'https://github.com/login/oauth/access_token';
|
|
|
|
}
|
|
|
|
|
2012-05-08 21:08:05 +02:00
|
|
|
protected function getTokenExpiryKey() {
|
|
|
|
// github access tokens do not have time-based expiry
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2012-02-17 18:55:16 +01:00
|
|
|
public function getTestURIs() {
|
|
|
|
return array(
|
2012-06-12 21:01:10 +02:00
|
|
|
'http://api.github.com',
|
2012-02-17 18:55:16 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-02-21 07:47:56 +01:00
|
|
|
public function getUserInfoURI() {
|
2012-06-12 21:01:10 +02:00
|
|
|
return 'https://api.github.com/user';
|
2011-02-21 07:47:56 +01:00
|
|
|
}
|
|
|
|
|
2011-02-23 19:27:33 +01:00
|
|
|
public function getMinimumScope() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2011-02-28 04:47:22 +01:00
|
|
|
public function setUserData($data) {
|
2012-06-12 21:01:10 +02:00
|
|
|
$data = json_decode($data, true);
|
2012-05-01 11:51:40 +02:00
|
|
|
$this->validateUserData($data);
|
|
|
|
$this->userData = $data;
|
2011-02-28 04:47:22 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function retrieveUserID() {
|
|
|
|
return $this->userData['id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function retrieveUserEmail() {
|
2011-05-07 02:01:00 +02:00
|
|
|
return idx($this->userData, 'email');
|
2011-02-28 04:47:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function retrieveUserAccountName() {
|
|
|
|
return $this->userData['login'];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function retrieveUserProfileImage() {
|
2012-06-12 21:01:10 +02:00
|
|
|
$uri = idx($this->userData, 'avatar_url');
|
|
|
|
if ($uri) {
|
2012-06-19 00:11:47 +02:00
|
|
|
return HTTPSFuture::loadContent($uri);
|
2011-02-28 04:47:22 +01:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function retrieveUserAccountURI() {
|
|
|
|
$username = $this->retrieveUserAccountName();
|
|
|
|
if ($username) {
|
|
|
|
return 'https://github.com/'.$username;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function retrieveUserRealName() {
|
2011-05-07 02:01:00 +02:00
|
|
|
return idx($this->userData, 'name');
|
2011-02-28 04:47:22 +01:00
|
|
|
}
|
|
|
|
|
2012-05-05 01:16:29 +02:00
|
|
|
public function shouldDiagnoseAppLogin() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-02-21 07:47:56 +01:00
|
|
|
}
|