From 028985a7dcc9e80b57233dd4fe456f86f66f28c2 Mon Sep 17 00:00:00 2001 From: Peter Elmered Date: Thu, 12 Sep 2024 23:10:35 +0200 Subject: [PATCH] Add example with objects to readme --- README.md | 27 +++++++++++++++++++++++++++ src/RefreshToken.php | 13 ------------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 096851d..6c005d7 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ + + # Laravel HTTP Client Auth helper An easy-to-use helper for Laravel HTTP Client to make manage API requests with a two-step auth flow. @@ -90,6 +92,31 @@ $response = Http::withRefreshToken( ); ``` +For full type safety, you can also provide objects instead of arrays: +```php +use Pelmered\LaravelHttpOAuthHelper\AccessToken; +use Pelmered\LaravelHttpOAuthHelper\Credentials; +use Pelmered\LaravelHttpOAuthHelper\Options; +use Pelmered\LaravelHttpOAuthHelper\RefreshToken; + +$response = Http::withRefreshToken( + 'https://example.com/token.oauth2', + new Credentials( + clientId: 'client_id', + clientSecret: 'client_secret', + authType: Credentials::AUTH_TYPE_BODY, + ), + new Options( + scopes: ['scope1', 'scope2'], + expires: 3600, + grantType: 'password_credentials', + tokenType: AccessToken::TYPE_BEARER + ), +)->get( + 'https://example.com/api', +); +``` + You can also provide callbacks for `expires`, `auth_type`, and `access_token` to customize the behavior. ```php $response = Http::withRefreshToken( diff --git a/src/RefreshToken.php b/src/RefreshToken.php index 0fbf5c2..dd891de 100644 --- a/src/RefreshToken.php +++ b/src/RefreshToken.php @@ -28,19 +28,6 @@ public function __invoke( Credentials $credentials, Options $options, ): AccessToken { - - //TODO: Refactor $options - - //dd($options); - /* - $options = array_merge([ - 'scopes' => [], - 'auth_type' => 'body', - 'expires' => 3600, - 'access_token' => 'access_token', - ], $options); - */ - $this->httpClient = Http::asForm(); $this->requestBody = [