rename app/library/OAuth.php to app/library/OAuth/Client.php and change implementation to use Adapter classes.
This commit is contained in:
parent
21c869a06a
commit
b3eb25d221
2 changed files with 59 additions and 103 deletions
59
app/library/OAuth/Client.php
Normal file
59
app/library/OAuth/Client.php
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
namespace Httpcb\OAuth;
|
||||
|
||||
use Httpcb\OAuth\Adapter\AdapterInterface;
|
||||
|
||||
class Client
|
||||
{
|
||||
/**
|
||||
* Adapter to use.
|
||||
*
|
||||
* @var AdapterInterface
|
||||
*/
|
||||
protected $_adapter;
|
||||
|
||||
/**
|
||||
* Access Token
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_token;
|
||||
|
||||
public function __construct(AdapterInterface $adapter)
|
||||
{
|
||||
$this->_adapter = $adapter;
|
||||
}
|
||||
|
||||
public function getAuthorizationUrl()
|
||||
{
|
||||
return $this->_adapter->getAuthorizationUrl();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
* @return UserDataInterface
|
||||
*/
|
||||
public function authenticate($code)
|
||||
{
|
||||
$this->_adapter->fetchAccessToken($code);
|
||||
|
||||
return $this->getUserData();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return UserDataInterface
|
||||
*/
|
||||
public function getUserData()
|
||||
{
|
||||
$data = $this->_adapter->getResourceData();
|
||||
return $this->_createUserData($data);
|
||||
}
|
||||
|
||||
protected function _createUserData(array $data)
|
||||
{
|
||||
$name = $this->_adapter->getProviderName();
|
||||
$class = "Httpcb\\OAuth\\UserData\\{$name}";
|
||||
return new $class($data);
|
||||
}
|
||||
}
|
||||
Reference in a new issue