You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+125-1Lines changed: 125 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -72,4 +72,128 @@ You can use the HeaderRequestSigner to add the access token in another header, o
72
72
73
73
A class in charge of checking if the API call failed because of a token expiration.
74
74
By default, the decorator uses StatusCode401ResponseChecker that identifies 401 response codes as the signal the access token needs to be renewed.
75
-
It can lead to false positives (401 response code can be returned for other reasons than token expiration), so you can implement the interface if your OAuth server returns exploitable fine-grained error reasons.
75
+
It can lead to false positives (401 response code can be returned for other reasons than token expiration), so you can implement the interface if your OAuth server returns exploitable fine-grained error reasons.
76
+
77
+
## Full Symfony-specific example
78
+
79
+
Here is a full example of how to use this library inside a Symfony application.
80
+
81
+
- with custom Grant Type
82
+
- with Redis as a cache layer
83
+
- with [scoped](https://symfony.com/doc/current/http_client.html#scoping-client) HTTP Client definition
84
+
- with different URLs for the OAuth server and the API
85
+
86
+
First of all, we need to define 2 HTTP Clients: one for the OAuth server and one for the API.
87
+
88
+
```yaml
89
+
framework:
90
+
http_client:
91
+
scoped_clients:
92
+
sharepoint_oauth.client:
93
+
scope: '%env(resolve:SHAREPOINT_OAUTH_URL)%'
94
+
headers:
95
+
Accept: 'application/json;odata=verbose'
96
+
# other specific headers or settings if needed
97
+
sharepoint_api.client:
98
+
scope: '%env(resolve:SHAREPOINT_API_URL)%'
99
+
headers:
100
+
Accept: 'application/json;odata=verbose'
101
+
# other specific headers or settings if needed
102
+
```
103
+
104
+
Second, we need to define a custom Grant Type that will fetch the access token from the OAuth server to connect to SharePoint and will use `sharepoint_oauth.client` defined above.
105
+
106
+
It differs from a built-in `ClientCredentialsGrantType` on purpose, to show how we can customize the authentication process:
107
+
108
+
```php
109
+
<?php
110
+
111
+
declare(strict_types=1);
112
+
113
+
namespace App\Sharepoint;
114
+
115
+
use BenjaminFavre\OAuthHttpClient\GrantType\GrantTypeInterface;
116
+
use BenjaminFavre\OAuthHttpClient\GrantType\Tokens;
117
+
use BenjaminFavre\OAuthHttpClient\GrantType\TokensExtractor;
118
+
use Symfony\Component\HttpFoundation\Request;
119
+
use Symfony\Contracts\HttpClient\HttpClientInterface;
120
+
121
+
final class CustomClientCredentialsGrantType implements GrantTypeInterface
0 commit comments