![]() ![]() Optionally, try again with a new access token if the first API call failed because of token expiration.Make the API call and return the response.Modify your request to add the access token (usually in a header).Fetch an access token from cache or from the OAuth server if none is in cache.Then use $httpClient to make your API calls: // $httpClient->request(.) How it worksĮach time you make an HTTP request, the decorator will: ![]() $httpClient = new OAuthHttpClient( $httpClient, $grantType) '', // The OAuth server token URL 'the-client-id', Here we will use the client credentials grant type but it could be any other grant type $grantType = new ClientCredentialsGrantType( Use BenjaminFavre\ OAuthHttpClient\ GrantType\ ClientCredentialsGrantType Use BenjaminFavre\ OAuthHttpClient\ OAuthHttpClient Usage use Symfony\ Component\ HttpClient\ HttpClient Installation composer require benjaminfavre/oauth2-http-client This is why the decorator has been designed such a way that every step of the authentication process is customizable. Too often however, the OAuth 2 server you will have to authenticate to will not follow strict OAuth 2 standard. This decorator aims to provide all standard Grant Types out of the box. OAuth 2 is a relatively complex protocol which offers to authenticate in a wide variety of manners (called Grant Types in the OAuth jargon). It handles all the authentication protocol with the OAuth 2 server and let you focus solely on making your business API calls.ĭesigned to be minimalist and lightweight, it has literally no dependency at all, apart the Symfony Contracts of course and it requires only the PHP JSON extension. A decorator for the Symfony HTTP Client that helps you call APIs endpoints protected with OAuth 2. ![]()
0 Comments
Leave a Reply. |