mirror of
https://github.com/e107inc/e107.git
synced 2025-08-05 22:27:34 +02:00
Adding Hybridauth 3.2.0 social login providers
Forgot to commit in a3d99f0d19
This commit is contained in:
134
e107_handlers/vendor/hybridauth/hybridauth/src/Provider/QQ.php
vendored
Normal file
134
e107_handlers/vendor/hybridauth/hybridauth/src/Provider/QQ.php
vendored
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hybridauth\Provider;
|
||||||
|
|
||||||
|
use Hybridauth\Adapter\OAuth2;
|
||||||
|
use Hybridauth\Exception\UnexpectedApiResponseException;
|
||||||
|
use Hybridauth\Data;
|
||||||
|
use Hybridauth\User\Profile;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tencent QQ International OAuth2 provider adapter.
|
||||||
|
*/
|
||||||
|
class QQ extends OAuth2
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected $scope = 'get_user_info';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected $apiBaseUrl = 'https://graph.qq.com/oauth2.0/';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected $authorizeUrl = 'https://graph.qq.com/oauth2.0/authorize';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected $accessTokenUrl = 'https://graph.qq.com/oauth2.0/token';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@ịnheritdoc}
|
||||||
|
*/
|
||||||
|
protected $accessTokenInfoUrl = 'https://graph.qq.com/oauth2.0/me';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User Information Endpoint
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $accessUserInfo = 'https://graph.qq.com/user/get_user_info';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected $tokenExchangeMethod = 'GET';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected $tokenRefreshMethod = 'GET';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function initialize()
|
||||||
|
{
|
||||||
|
parent::initialize();
|
||||||
|
|
||||||
|
$this->tokenRefreshParameters = [
|
||||||
|
'grant_type' => 'refresh_token',
|
||||||
|
'client_id' => $this->clientId,
|
||||||
|
'client_secret' => $this->clientSecret,
|
||||||
|
'refresh_token' => $this->getStoredData('refresh_token'),
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->apiRequestParameters = [
|
||||||
|
'access_token' => $this->getStoredData('access_token')
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->apiRequestHeaders = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function validateAccessTokenExchange($response)
|
||||||
|
{
|
||||||
|
$collection = parent::validateAccessTokenExchange($response);
|
||||||
|
|
||||||
|
$resp = $this->apiRequest($this->accessTokenInfoUrl);
|
||||||
|
$resp = key($resp);
|
||||||
|
|
||||||
|
$len = strlen($resp);
|
||||||
|
$res = substr($resp, 10, $len - 14);
|
||||||
|
|
||||||
|
$response = (new Data\Parser())->parse($res);
|
||||||
|
|
||||||
|
if (!isset($response->openid)) {
|
||||||
|
throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->storeData('openid', $response->openid);
|
||||||
|
|
||||||
|
return $collection;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getUserProfile()
|
||||||
|
{
|
||||||
|
$openid = $this->getStoredData('openid');
|
||||||
|
|
||||||
|
$userRequestParameters = [
|
||||||
|
'oauth_consumer_key' => $this->clientId,
|
||||||
|
'openid' => $openid,
|
||||||
|
'format' => 'json'
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $this->apiRequest($this->accessUserInfo, 'GET', $userRequestParameters);
|
||||||
|
|
||||||
|
$data = new Data\Collection($response);
|
||||||
|
|
||||||
|
if ($data->get('ret') < 0) {
|
||||||
|
throw new UnexpectedApiResponseException('Provider API returned an error: ' . $data->get('msg'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$userProfile = new Profile();
|
||||||
|
|
||||||
|
$userProfile->identifier = $openid;
|
||||||
|
$userProfile->displayName = $data->get('nickname');
|
||||||
|
$userProfile->photoURL = $data->get('figureurl_2');
|
||||||
|
$userProfile->gender = $data->get('gender');
|
||||||
|
$userProfile->region = $data->get('province');
|
||||||
|
$userProfile->city = $data->get('city');
|
||||||
|
|
||||||
|
return $userProfile;
|
||||||
|
}
|
||||||
|
}
|
101
e107_handlers/vendor/hybridauth/hybridauth/src/Provider/Slack.php
vendored
Normal file
101
e107_handlers/vendor/hybridauth/hybridauth/src/Provider/Slack.php
vendored
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
<?php
|
||||||
|
/*!
|
||||||
|
* Hybridauth
|
||||||
|
* https://hybridauth.github.io | https://github.com/hybridauth/hybridauth
|
||||||
|
* (c) 2019 Hybridauth authors | https://hybridauth.github.io/license.html
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Hybridauth\Provider;
|
||||||
|
|
||||||
|
use Hybridauth\Adapter\OAuth2;
|
||||||
|
use Hybridauth\Exception\UnexpectedApiResponseException;
|
||||||
|
use Hybridauth\Data;
|
||||||
|
use Hybridauth\User;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Slack OAuth2 provider adapter.
|
||||||
|
*/
|
||||||
|
class Slack extends OAuth2
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public $scope = 'identity.basic identity.email identity.avatar';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected $apiBaseUrl = 'https://slack.com/';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected $authorizeUrl = 'https://slack.com/oauth/authorize';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected $accessTokenUrl = 'https://slack.com/api/oauth.access';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected $apiDocumentation = 'https://api.slack.com/docs/sign-in-with-slack';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getUserProfile()
|
||||||
|
{
|
||||||
|
$response = $this->apiRequest('api/users.identity');
|
||||||
|
|
||||||
|
$data = new Data\Collection($response);
|
||||||
|
|
||||||
|
if (!$data->exists('ok') || !$data->get('ok')) {
|
||||||
|
throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$userProfile = new User\Profile();
|
||||||
|
|
||||||
|
$userProfile->identifier = $data->filter('user')->get('id');
|
||||||
|
$userProfile->displayName = $data->filter('user')->get('name');
|
||||||
|
$userProfile->email = $data->filter('user')->get('email');
|
||||||
|
$userProfile->photoURL = $this->findLargestImage($data);
|
||||||
|
|
||||||
|
return $userProfile;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the url of the image with the highest resolution in the user
|
||||||
|
* object.
|
||||||
|
*
|
||||||
|
* Slack sends multiple image urls with different resolutions. As they make
|
||||||
|
* no guarantees which resolutions will be included we have to search all
|
||||||
|
* <code>image_*</code> properties for the one with the highest resolution.
|
||||||
|
* The resolution is attached to the property name such as
|
||||||
|
* <code>image_32</code> or <code>image_192</code>.
|
||||||
|
*
|
||||||
|
* @param Data\Collection $data response object as returned by
|
||||||
|
* <code>api/users.identity</code>
|
||||||
|
*
|
||||||
|
* @return string|null the value of the <code>image_*</code> property with
|
||||||
|
* the highest resolution.
|
||||||
|
*/
|
||||||
|
private function findLargestImage(Data\Collection $data)
|
||||||
|
{
|
||||||
|
$maxSize = 0;
|
||||||
|
foreach ($data->filter('user')->properties() as $property) {
|
||||||
|
if (preg_match('/^image_(\d+)$/', $property, $matches) === 1) {
|
||||||
|
$availableSize = (int)$matches[1];
|
||||||
|
if ($maxSize < $availableSize) {
|
||||||
|
$maxSize = $availableSize;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($maxSize > 0) {
|
||||||
|
return $data->filter('user')->get('image_' . $maxSize);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
72
e107_handlers/vendor/hybridauth/hybridauth/src/Provider/Strava.php
vendored
Normal file
72
e107_handlers/vendor/hybridauth/hybridauth/src/Provider/Strava.php
vendored
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
<?php
|
||||||
|
/*!
|
||||||
|
* Hybridauth
|
||||||
|
* https://hybridauth.github.io | https://github.com/hybridauth/hybridauth
|
||||||
|
* (c) 2017 Hybridauth authors | https://hybridauth.github.io/license.html
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Hybridauth\Provider;
|
||||||
|
|
||||||
|
use Hybridauth\Adapter\OAuth2;
|
||||||
|
use Hybridauth\Exception\UnexpectedApiResponseException;
|
||||||
|
use Hybridauth\Data;
|
||||||
|
use Hybridauth\User;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GitLab OAuth2 provider adapter.
|
||||||
|
*/
|
||||||
|
class Strava extends OAuth2
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public $scope = 'profile:read_all';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected $apiBaseUrl = 'https://www.strava.com/api/v3/';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected $authorizeUrl = 'https://www.strava.com/oauth/authorize';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected $accessTokenUrl = 'https://www.strava.com/oauth/token';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected $apiDocumentation = 'https://developers.strava.com/docs/reference/';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getUserProfile()
|
||||||
|
{
|
||||||
|
$response = $this->apiRequest('athlete');
|
||||||
|
|
||||||
|
$data = new Data\Collection($response);
|
||||||
|
|
||||||
|
if (! $data->exists('id')) {
|
||||||
|
throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$userProfile = new User\Profile();
|
||||||
|
|
||||||
|
$userProfile->identifier = $data->get('id');
|
||||||
|
$userProfile->firstName = $data->get('firstname');
|
||||||
|
$userProfile->lastName = $data->get('lastname');
|
||||||
|
$userProfile->gender = $data->get('sex');
|
||||||
|
$userProfile->country = $data->get('country');
|
||||||
|
$userProfile->city = $data->get('city');
|
||||||
|
$userProfile->email = $data->get('email');
|
||||||
|
|
||||||
|
$userProfile->displayName = $userProfile->displayName ?: $data->get('username');
|
||||||
|
|
||||||
|
return $userProfile;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user