Skip to content

Commit

Permalink
Add example with objects to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
pelmered committed Sep 12, 2024
1 parent 882951e commit 028985a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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(
Expand Down
13 changes: 0 additions & 13 deletions src/RefreshToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down

0 comments on commit 028985a

Please sign in to comment.