Skip to content

Commit

Permalink
Code style
Browse files Browse the repository at this point in the history
  • Loading branch information
pelmered committed Sep 12, 2024
1 parent 4e0aad5 commit dae0a91
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 17 deletions.
7 changes: 4 additions & 3 deletions src/Credentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ class Credentials

public const AUTH_TYPE_CUSTOM = 'custom';


public const GRANT_TYPE_CLIENT_CREDENTIALS = 'client_credentials';

public const GRANT_TYPE_PASSWORD_CREDENTIALS = 'password_credentials';

//TODO: Add support for authorization_code and implicit grants
public const GRANT_TYPE_AUTHORIZATION_CODE = 'authorization_code';

public const GRANT_TYPE_IMPLICIT = 'implicit';

private ?\Closure $customCallback;
Expand Down Expand Up @@ -52,9 +53,9 @@ public function __construct(
//$this->validate();
}

protected function validate( ): void
protected function validate(): void
{
Validator::make((array)$this, [
Validator::make((array) $this, [
'grantType' => Rule::in([self::GRANT_TYPE_CLIENT_CREDENTIALS, self::GRANT_TYPE_PASSWORD_CREDENTIALS]),
'authType' => Rule::in([self::AUTH_TYPE_BEARER, self::AUTH_TYPE_BODY, self::AUTH_TYPE_QUERY, self::AUTH_TYPE_BASIC, self::AUTH_TYPE_CUSTOM]),
])->validate();
Expand Down
15 changes: 8 additions & 7 deletions src/Options.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Pelmered\LaravelHttpOAuthHelper;

use Illuminate\Support\Facades\Validator;
Expand All @@ -7,22 +8,22 @@
class Options
{
final public function __construct(
public array $scopes = [],
public string $grantType = 'client_credentials',
public string $tokenType = AccessToken::TYPE_BEARER,
public array $scopes = [],
public string $grantType = 'client_credentials',
public string $tokenType = AccessToken::TYPE_BEARER,
public int|string|\Closure $expires = 3600,
public string|\Closure $accessToken = 'access_token',
public ?\Closure $tokenTypeCustomCallback = null,
public string|\Closure $accessToken = 'access_token',
public ?\Closure $tokenTypeCustomCallback = null,
) {
$this->validateOptions();
}

/**
* @param array<string, mixed> $options
*/
protected function validateOptions( ): void
protected function validateOptions(): void
{
Validator::make((array)$this, [
Validator::make((array) $this, [
'tokenType' => Rule::in([AccessToken::TYPE_BEARER, AccessToken::TYPE_QUERY, AccessToken::TYPE_CUSTOM]),
])->validate();
}
Expand Down
3 changes: 0 additions & 3 deletions src/RefreshToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Illuminate\Http\Client\PendingRequest;
use Illuminate\Http\Client\Response;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Validator;
use InvalidArgumentException;

class RefreshToken
Expand Down Expand Up @@ -62,8 +61,6 @@ public function __invoke(
);
}



protected function resolveRefreshAuth(Credentials $credentials): void
{
$this->httpClient = $credentials->addAuthToRequest($this->httpClient);
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/MacroTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ function (Request $request) {
clientSecret: 'this_is_my_client_secret',
),
[
'scopes' => ['scope1', 'scope2'],
'tokenType' => AccessToken::TYPE_QUERY
'scopes' => ['scope1', 'scope2'],
'tokenType' => AccessToken::TYPE_QUERY,
],
)->get('https://example.com/api');

Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/RefreshTokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
new Credentials([
'my_client_id',
'my_client_secret',
Credentials::AUTH_TYPE_BODY
Credentials::AUTH_TYPE_BODY,
]),
new Options(
scopes: ['scope1', 'scope2'],
Expand Down
1 change: 0 additions & 1 deletion tests/Unit/TokenStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
uses(\Pelmered\LaravelHttpOAuthHelper\Tests\TestCase::class);

use Illuminate\Support\Facades\Cache;
use Pelmered\LaravelHttpOAuthHelper\AccessToken;
use Pelmered\LaravelHttpOAuthHelper\Credentials;
use Pelmered\LaravelHttpOAuthHelper\Options;
use Pelmered\LaravelHttpOAuthHelper\TokenStore;
Expand Down

0 comments on commit dae0a91

Please sign in to comment.