Download the PHP package benjaminfavre/oauth2-http-client without Composer

On this page you can find all versions of the php package benjaminfavre/oauth2-http-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package oauth2-http-client

OAuth 2 decorator for the Symfony HTTP Client

A decorator for the Symfony HTTP Client that helps you call APIs endpoints protected with OAuth 2. It handles all the authentication protocol with the OAuth 2 server and let you focus solely on making your business API calls.

Designed 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.

OAuth 2 is a relatively complex protocol which offers to authenticate in a wide variety of manners (called Grant Types in the OAuth jargon). This decorator aims to provide all standard Grant Types out of the box. Too often however, the OAuth 2 server you will have to authenticate to will not follow strict OAuth 2 standard. This is why the decorator has been designed such a way that every step of the authentication process is customizable.

Installation

composer require benjaminfavre/oauth2-http-client

Usage

How it works

Each time you make an HTTP request, the decorator will:

Customization

Implement any of the following interfaces in order to customize the relevant authentication step, and pass an instance of your class via the relevant Decorator setter.

GrantTypeInterface

A class in charge of fetching an access token from the OAuth server. The decorator comes with four standard grant types:

TokensCacheInterface

A class in charge of storing and fetching tokens from cache. By default, the decorator uses MemoryTokensCache that caches the tokens in memory.

RequestSignerInterface

A class in charge of modifying the API request in order to add the access token. By default, the decorator uses BearerHeaderRequestSigner that adds the access token in the Authorization header. You can use the HeaderRequestSigner to add the access token in another header, or you can implement the interface for more customization.

ResponseCheckerInterface

A class in charge of checking if the API call failed because of a token expiration. By default, the decorator uses StatusCode401ResponseChecker that identifies 401 response codes as the signal the access token needs to be renewed. 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.

Full Symfony-specific example

Here is a full example of how to use this library inside a Symfony application.

First of all, we need to define 2 HTTP Clients: one for the OAuth server and one for the API.

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.

It differs from a built-in ClientCredentialsGrantType on purpose, to show how we can customize the authentication process:

In order to pass the required parameters to the Grant Type, we need to define the service in service.yaml and bind parameters:

Then, we need to define our cache layer instead of default in-memory, by adding the following service definition to services.yaml:

@cache.app is an application cache, configured in your system. In our example, this is a Redis cache:

Finally, we can define our OAuthHttpClient service in services.yaml that uses sharepoint_api.client and sets configured Redis cache:

After this, OAuthHttpClient service is ready to be used in your application in any other classes:


All versions of oauth2-http-client with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
ext-json Version *
symfony/cache-contracts Version ^3.0
symfony/http-client-contracts Version ^3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package benjaminfavre/oauth2-http-client contains the following files

Loading the files please wait ....