Skip to content

Commit

Permalink
add some suggested changes from SocialiteProviders#1162
Browse files Browse the repository at this point in the history
  • Loading branch information
macbookandrew committed Mar 5, 2024
1 parent c34c3b8 commit 8dba06f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/Clover/CloverExtendSocialite.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class CloverExtendSocialite
{
public function handle(SocialiteWasCalled $socialiteWasCalled)
public function handle(SocialiteWasCalled $socialiteWasCalled): void
{
$socialiteWasCalled->extendSocialite(Provider::IDENTIFIER, Provider::class);
}
Expand Down
18 changes: 6 additions & 12 deletions src/Clover/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Provider extends AbstractProvider
*/
protected $stateless = true;

public static function additionalConfigKeys()
public static function additionalConfigKeys(): array
{
return [
'environment',
Expand All @@ -37,9 +37,8 @@ public static function additionalConfigKeys()
* Get the access token response for the given code.
*
* @param string $code
* @return array
*/
public function getAccessTokenResponse($code)
public function getAccessTokenResponse($code): array
{
$response = $this->getHttpClient()->post($this->getTokenUrl(), [
RequestOptions::HEADERS => $this->getTokenHeaders($code),
Expand All @@ -60,7 +59,7 @@ protected function getApiDomain(): string
/**
* {@inheritdoc}
*/
protected function getAuthUrl($state)
protected function getAuthUrl($state): string
{
return $this->buildAuthUrlFromBase(
sprintf('https://%s/oauth/v2/authorize', $this->getApiDomain()),
Expand All @@ -71,7 +70,7 @@ protected function getAuthUrl($state)
/**
* {@inheritdoc}
*/
protected function getTokenUrl()
protected function getTokenUrl(): string
{
$domain = match ($this->getConfig('environment')) {
'sandbox' => 'apisandbox.dev.clover.com',
Expand All @@ -86,16 +85,11 @@ protected function getTokenUrl()
*/
protected function getUserByToken($token)
{
$requestParams = str(request()->fullUrl())
->after('?')
->explode('&')
->mapWithKeys(fn (string $keyAndValue) => [str($keyAndValue)->before('=')->toString() => str($keyAndValue)->after('=')->toString()]);

$response = $this->getHttpClient()->get(sprintf(
'https://%s/v3/merchants/%s/employees/%s',
$this->getApiDomain(),
$requestParams['merchant_id'],
$requestParams['employee_id'],
$this->request->query('merchant_id'),
$this->request->query('employee_id'),
), [
'headers' => [
'Authorization' => 'Bearer '.$token,
Expand Down
2 changes: 1 addition & 1 deletion src/Clover/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Add the event to your `listen[]` array in `app/Providers/EventServiceProvider`.
protected $listen = [
\SocialiteProviders\Manager\SocialiteWasCalled::class => [
// ... other providers
'SocialiteProviders\\Clover\\CloverExtendSocialite@handle',
\SocialiteProviders\Clover\CloverExtendSocialite::class.'@handle',
],
];
```
Expand Down
14 changes: 13 additions & 1 deletion src/Clover/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,28 @@
"name": "socialiteproviders/clover",
"description": "Clover OAuth2 Provider for Laravel Socialite",
"license": "MIT",
"keywords": [
"clover",
"laravel",
"oauth",
"provider",
"socialite"
],
"authors": [
{
"name": "macbookandrew",
"homepage": "https://andrewrminion.com"
}
],
"support": {
"issues": "https://github.com/socialiteproviders/providers/issues",
"source": "https://github.com/socialiteproviders/providers",
"docs": "https://socialiteproviders.com/clover"
},
"require": {
"php": "^8.1",
"ext-json": "*",
"socialiteproviders/manager": "^4.0"
"socialiteproviders/manager": "^4.4"
},
"autoload": {
"psr-4": {
Expand Down

0 comments on commit 8dba06f

Please sign in to comment.