-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
165 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,91 +1,91 @@ | ||
<?php | ||
|
||
namespace CFreear\OAuth2\Client\Provider; | ||
|
||
use League\OAuth2\Client\Provider\AbstractProvider; | ||
use League\OAuth2\Client\Provider\Exception\IdentityProviderException; | ||
use League\OAuth2\Client\Provider\ResourceOwnerInterface; | ||
use League\OAuth2\Client\Token\AccessToken; | ||
use League\OAuth2\Client\Tool\BearerAuthorizationTrait; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
class MailChimp extends AbstractProvider | ||
{ | ||
use BearerAuthorizationTrait; | ||
|
||
/** | ||
* Returns the base URL for authorizing a client. | ||
* | ||
* @return string | ||
*/ | ||
public function getBaseAuthorizationUrl() | ||
{ | ||
return 'https://login.mailchimp.com/oauth2/authorize'; | ||
} | ||
|
||
/** | ||
* Returns the base URL for requesting an access token. | ||
* | ||
* @param array $params | ||
* @return string | ||
*/ | ||
public function getBaseAccessTokenUrl(array $params) | ||
{ | ||
return 'https://login.mailchimp.com/oauth2/token'; | ||
} | ||
|
||
/** | ||
* Returns the URL for requesting the resource owner's details. | ||
* | ||
* @param AccessToken $token | ||
* @return string | ||
*/ | ||
public function getResourceOwnerDetailsUrl(AccessToken $token) | ||
{ | ||
return 'https://login.mailchimp.com/oauth2/metadata'; | ||
} | ||
|
||
/** | ||
* Returns the default scopes used by this provider. | ||
* | ||
* No scopes for MailChimp! | ||
* | ||
* @return array | ||
*/ | ||
protected function getDefaultScopes() | ||
{ | ||
return []; | ||
} | ||
|
||
/** | ||
* Checks a provider response for errors. | ||
* | ||
* @throws IdentityProviderException | ||
* @param ResponseInterface $response | ||
* @param array|string $data Parsed response data | ||
* @return void | ||
*/ | ||
protected function checkResponse(ResponseInterface $response, $data) | ||
{ | ||
if ($response->getStatusCode() >= 400) { | ||
throw new IdentityProviderException( | ||
$data['error'] ?: $response->getReasonPhrase(), | ||
$response->getStatusCode(), | ||
$response | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* Generates a resource owner object from a successful resource owner | ||
* details request. | ||
* | ||
* @param array $response | ||
* @param AccessToken $token | ||
* @return ResourceOwnerInterface | ||
*/ | ||
protected function createResourceOwner(array $response, AccessToken $token) | ||
{ | ||
return new MailChimpResourceOwner($response); | ||
} | ||
} | ||
<?php | ||
|
||
namespace CFreear\OAuth2\Client\Provider; | ||
|
||
use League\OAuth2\Client\Provider\AbstractProvider; | ||
use League\OAuth2\Client\Provider\Exception\IdentityProviderException; | ||
use League\OAuth2\Client\Provider\ResourceOwnerInterface; | ||
use League\OAuth2\Client\Token\AccessToken; | ||
use League\OAuth2\Client\Tool\BearerAuthorizationTrait; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
class MailChimp extends AbstractProvider | ||
{ | ||
use BearerAuthorizationTrait; | ||
|
||
/** | ||
* Returns the base URL for authorizing a client. | ||
* | ||
* @return string | ||
*/ | ||
public function getBaseAuthorizationUrl() | ||
{ | ||
return 'https://login.mailchimp.com/oauth2/authorize'; | ||
} | ||
|
||
/** | ||
* Returns the base URL for requesting an access token. | ||
* | ||
* @param array $params | ||
* @return string | ||
*/ | ||
public function getBaseAccessTokenUrl(array $params) | ||
{ | ||
return 'https://login.mailchimp.com/oauth2/token'; | ||
} | ||
|
||
/** | ||
* Returns the URL for requesting the resource owner's details. | ||
* | ||
* @param AccessToken $token | ||
* @return string | ||
*/ | ||
public function getResourceOwnerDetailsUrl(AccessToken $token) | ||
{ | ||
return 'https://login.mailchimp.com/oauth2/metadata'; | ||
} | ||
|
||
/** | ||
* Returns the default scopes used by this provider. | ||
* | ||
* No scopes for MailChimp! | ||
* | ||
* @return array | ||
*/ | ||
protected function getDefaultScopes() | ||
{ | ||
return []; | ||
} | ||
|
||
/** | ||
* Checks a provider response for errors. | ||
* | ||
* @throws IdentityProviderException | ||
* @param ResponseInterface $response | ||
* @param array|string $data Parsed response data | ||
* @return void | ||
*/ | ||
protected function checkResponse(ResponseInterface $response, $data) | ||
{ | ||
if ($response->getStatusCode() >= 400) { | ||
throw new IdentityProviderException( | ||
$data['error'] ?: $response->getReasonPhrase(), | ||
$response->getStatusCode(), | ||
$response | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* Generates a resource owner object from a successful resource owner | ||
* details request. | ||
* | ||
* @param array $response | ||
* @param AccessToken $token | ||
* @return ResourceOwnerInterface | ||
*/ | ||
protected function createResourceOwner(array $response, AccessToken $token) | ||
{ | ||
return new MailChimpResourceOwner($response); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,74 @@ | ||
<?php | ||
|
||
namespace CFreear\OAuth2\Client\Provider; | ||
|
||
use League\OAuth2\Client\Provider\ResourceOwnerInterface; | ||
|
||
class MailChimpResourceOwner implements ResourceOwnerInterface | ||
{ | ||
/** | ||
* Raw response | ||
* @var | ||
*/ | ||
protected $response; | ||
|
||
/** | ||
* Set response | ||
* | ||
* @param array $response | ||
*/ | ||
public function __construct(array $response) | ||
{ | ||
$this->response = $response; | ||
} | ||
|
||
/** | ||
* Returns empty id as MailChimp doesn't respond with an identifier. | ||
* | ||
* @return string | ||
*/ | ||
public function getId() | ||
{ | ||
return ''; | ||
} | ||
|
||
/** | ||
* Return all of the owner details available as an array. | ||
* | ||
* @return array | ||
*/ | ||
public function toArray() | ||
{ | ||
return $this->response; | ||
} | ||
|
||
/** | ||
* Get the data center identifier. | ||
* | ||
* @return array | ||
*/ | ||
public function getDC() | ||
{ | ||
return $this->response['dc']; | ||
} | ||
|
||
/** | ||
* Get the api endpoint. | ||
* | ||
* @return array | ||
*/ | ||
public function getAPIEndpoint() | ||
{ | ||
return $this->response['api_endpoint']; | ||
} | ||
|
||
/** | ||
* Get the login url. | ||
* | ||
* @return array | ||
*/ | ||
public function getLoginURL() | ||
{ | ||
return $this->response['login_url']; | ||
} | ||
} | ||
<?php | ||
|
||
namespace CFreear\OAuth2\Client\Provider; | ||
|
||
use League\OAuth2\Client\Provider\ResourceOwnerInterface; | ||
|
||
class MailChimpResourceOwner implements ResourceOwnerInterface | ||
{ | ||
/** | ||
* Raw response | ||
* @var | ||
*/ | ||
protected $response; | ||
|
||
/** | ||
* Set response | ||
* | ||
* @param array $response | ||
*/ | ||
public function __construct(array $response) | ||
{ | ||
$this->response = $response; | ||
} | ||
|
||
/** | ||
* Returns empty id as MailChimp doesn't respond with an identifier. | ||
* | ||
* @return string | ||
*/ | ||
public function getId() | ||
{ | ||
return ''; | ||
} | ||
|
||
/** | ||
* Return all of the owner details available as an array. | ||
* | ||
* @return array | ||
*/ | ||
public function toArray() | ||
{ | ||
return $this->response; | ||
} | ||
|
||
/** | ||
* Get the data center identifier. | ||
* | ||
* @return array | ||
*/ | ||
public function getDC() | ||
{ | ||
return $this->response['dc']; | ||
} | ||
|
||
/** | ||
* Get the api endpoint. | ||
* | ||
* @return array | ||
*/ | ||
public function getAPIEndpoint() | ||
{ | ||
return $this->response['api_endpoint']; | ||
} | ||
|
||
/** | ||
* Get the login url. | ||
* | ||
* @return array | ||
*/ | ||
public function getLoginURL() | ||
{ | ||
return $this->response['login_url']; | ||
} | ||
} |