Skip to content

Commit d8e2862

Browse files
committed
Update Readme
1 parent c2dc62f commit d8e2862

File tree

2 files changed

+103
-6
lines changed

2 files changed

+103
-6
lines changed

README.md

+101-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
# Laravel HTTP Client Auth helper
42

53
An easy-to-use helper for Laravel HTTP Client to make manage API requests with a two-step auth flow.
@@ -13,6 +11,13 @@ This helper takes care of all the headaches and boilerplate code with a simple a
1311
- Extends the Laravel HTTP Client to make it straightforward to use. Se the [usage section](#usage) below for examples.
1412
- Supports common auth flows like OAuth2 and refresh tokens with most grant types.
1513

14+
#### Vision, roadmap & plans for the future
15+
16+
I want to support as many common auth flows as possible.\
17+
If you have a use case that is not super obscure,
18+
please [open an issue](https://github.com/pelmered/laravel-http-client-auth-helper/issues/new) where you provide as much detail as possible,
19+
or [submit a PR](https://github.com/pelmered/laravel-http-client-auth-helper/pulls).
20+
1621
#### Note: the API is not yet stable and the documentation is in the process of being updated. I hope I can release a version 1 soon.
1722

1823
#### TODO before stable 1.0.0 version:
@@ -41,6 +46,33 @@ This helper takes care of all the headaches and boilerplate code with a simple a
4146
[![Tested on PHP 8.1 to 8.4](https://img.shields.io/badge/Tested%20on%20PHP-8.1%20|%208.2%20|%208.3%20|%208.4-brightgreen.svg?maxAge=2419200)](https://github.com/pelmered/filament-money-field/actions/workflows/tests.yml)
4247
[![Tested on OS:es Linux, MacOS, Windows](https://img.shields.io/badge/Tested%20on%20lastest%20versions%20of-%20Ubuntu%20|%20MacOS%20|%20Windows-brightgreen.svg?maxAge=2419200)](https://github.com/pelmered/laravel-http-client-auth-helper/actions/workflows/tests.yml)
4348

49+
<!-- toc -->
50+
51+
- [Requirements](#requirements)
52+
- [Vision, roadmap & plans for the future](#vision-roadmap--plans-for-the-future)
53+
- [Contributing](#contributing)
54+
* [Issues & Bug Reports](#issues--bug-reports)
55+
- [Installation](#installation)
56+
- [Options reference](#options-reference)
57+
+ [scopes - `array`](#scopes---array)
58+
+ [authType - `string`](#authtype---string)
59+
+ [grantType - `string`](#granttype---string)
60+
+ [tokenType - `string`](#tokentype---string)
61+
+ [tokenName - `string`](#tokenname---string)
62+
+ [expires - `int|string|Closure|Carbon`](#expires---intstringclosurecarbon)
63+
+ [accessToken - `string|Closure`](#accesstoken---stringclosure)
64+
+ [tokenTypeCustomCallback - `?Closure`](#tokentypecustomcallback---closure)
65+
+ [cacheKey - `?string`](#cachekey---string)
66+
+ [cacheDriver - `?string`](#cachedriver---string)
67+
- [Usage](#usage)
68+
+ [Minimal example:](#minimal-example)
69+
+ [All parameters with default values:](#all-parameters-with-default-values)
70+
+ [For full type safety, you can also provide objects instead of arrays:](#for-full-type-safety-you-can-also-provide-objects-instead-of-arrays)
71+
+ [Customize with callbacks](#customize-with-callbacks)
72+
* [Integration tips](#integration-tips)
73+
74+
<!-- tocstop -->
75+
4476
## Requirements
4577

4678
- PHP 8.2 or higher
@@ -68,11 +100,74 @@ I will try to fix reported issues as soon as possible, but I do this in my spare
68100
composer require pelmered/laravel-http-client-auth-helper
69101
```
70102

103+
## Options reference
104+
105+
#### scopes - `array`
106+
Scopes to send when requesting an access token.
107+
Typically only used for OAuth2 flows.\
108+
**Possible options:** array with strings
109+
**Default:** `[]`
110+
111+
#### authType - `string`
112+
The type of authorization for the refresh token request.\
113+
**Possible options:** `Credentials::AUTH_TYPE_BEARER`, `Credentials::AUTH_TYPE_BODY`, `Credentials::AUTH_TYPE_QUERY`, `Credentials::AUTH_TYPE_BASIC`, `Credentials::AUTH_TYPE_CUSTOM`,\
114+
**Default:** `Credentials::AUTH_TYPE_BEARER` (=`'Bearer'`)
115+
116+
#### grantType - `string`
117+
Grant type for OAuth2 flows.
118+
**Possible options:** `Credentials::GRANT_TYPE_CLIENT_CREDENTIALS`, `Credentials::GRANT_TYPE_PASSWORD_CREDENTIALS` (authorization_code and implicit grants are not yet supported. See [issue #3](https://github.com/pelmered/laravel-http-client-auth-helper/issues/3))
119+
**Default:** `Credentials::GRANT_TYPE_CLIENT_CREDENTIALS` (=`'client_credentials'`)
120+
121+
#### tokenType - `string`
122+
How the access token should be applied to all subsequent requests.
123+
124+
**Possible options:** `AccessToken::TOKEN_TYPE_BEARER`,`AccessToken::TOKEN_TYPE_QUERY`,`AccessToken::TOKEN_TYPE_CUSTOM`,
125+
**Default:** `AccessToken::TOKEN_TYPE_BEARER` (=`'Bearer'`)
126+
127+
#### tokenName - `string`
128+
The name of the token field. This only applies for when the token is applied as a query parameter or to the body of the request.
129+
**Possible options:** Any string
130+
**Default:** `'token'`
131+
132+
#### expires - `int|string|Closure|Carbon`
133+
This determines when the access token expires.\
134+
**Possible options:** \
135+
integer - for how long until expiry in seconds)\
136+
string - Can be key of the field in response that contains the expiry of the token. Can also be a string with a date. This is then parsed by Carbon::parse so any format that Carbon can parse is acceptable.\
137+
Closure - A closure that receives the refresh response and can return any other acceptable value (integer, string or Carbon object).\
138+
Carbon - A Carbon object with the time of the expiry.\
139+
**Default:** 3600
140+
141+
#### accessToken - `string|Closure`
142+
This is where the access token can be found on the refresh response.\
143+
**Possible options:**\
144+
string - The key of the access token in the refresh response.\
145+
Closure - A closure that receives the refresh response and should return the token as a string.\
146+
**Default:** `'access_token'`
147+
148+
#### tokenTypeCustomCallback - `?Closure`
149+
A callback for giving dull control of how the authentication should be applied.
150+
The closure receives the Http client and should return a new Http Client where the auth information has been appended.\
151+
**Possible options:**\ Any closure that returns a Http Client (`Illuminate\Http\Client\PendingRequest`).\
152+
**Default:** `null`
153+
154+
#### cacheKey - `?string`
155+
The cache key that should be used to save the access tokens.
156+
If left empty, it will be generated based on the refresh URL.\
157+
**Possible options:**\
158+
**Default:** `null`
159+
160+
#### cacheDriver - `?string`
161+
The cache driver/store that should be used for storing the access tokens.
162+
If left empty, the Laravel default will be used.\
163+
**Possible options:**\
164+
**Default:** `null`
165+
71166
## Usage
72167

73168
It's really simple to use. Just add the `withRefreshToken` method to your HTTP request and provide the necessary parameters. No configuration needed.
74169

75-
Minimal example:
170+
#### Minimal example:
76171
```php
77172
$response = Http::withRefreshToken(
78173
'https://example.com/token.oauth2',
@@ -85,7 +180,7 @@ $response = Http::withRefreshToken(
85180
);
86181
```
87182

88-
All parameters with default values:
183+
#### All parameters with default values:
89184
```php
90185
$response = Http::withRefreshToken(
91186
'https://example.com/token.oauth2',
@@ -105,7 +200,7 @@ $response = Http::withRefreshToken(
105200
);
106201
```
107202

108-
For full type safety, you can also provide objects instead of arrays:
203+
#### For full type safety, you can also provide objects instead of arrays:
109204

110205
```php
111206
use Pelmered\LaravelHttpOAuthHelper\AccessToken;
@@ -131,6 +226,7 @@ $response = Http::withRefreshToken(
131226
);
132227
```
133228

229+
#### Customize with callbacks
134230
You can also provide callbacks for `expires`, `auth_type`, and `access_token` to customize the behavior.
135231
```php
136232
$response = Http::withRefreshToken(

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@
6666
],
6767
"type": [
6868
"@php vendor/bin/pest --type-coverage"
69-
]
69+
],
70+
"update-readme-toc": "markdown-toc -i README.md"
7071
},
7172
"config": {
7273
"allow-plugins": {

0 commit comments

Comments
 (0)