Download the PHP package pelmered/laravel-http-client-auth-helper without Composer

On this page you can find all versions of the php package pelmered/laravel-http-client-auth-helper. 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 laravel-http-client-auth-helper

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. For example, OAuth2 or refresh tokens to get a new short-lived access token.\ This helper takes care of all the headaches and boilerplate code with a simple and easy-to-use interface.

Features:

Vision, roadmap & plans for the future

I want to support as many common auth flows as possible.\ If you have a use case that is not super obscure, please open an issue where you provide as much detail as possible, or submit a PR with a working solution.

Plans for 1.1 - Milestone

Latest Stable Version License

Tests Build Status Scrutinizer Code Quality Code Coverage

Tested on PHP 8.2 to 8.4 Tested on OS:es Linux, MacOS, Windows

Table of contents

Requirements

Vision, roadmap & plans for the future

I want to support as many common auth flows as possible.\ If you have a use case that is not super obscure, please open an issue where you provide as much detail as possible, or submit a PR.

Contributing

See Contribution Guide before sending pull requests.

Issues & Bug Reports

When you are submitting issues, I appreciate if you could provide a failing test case. That makes my job a lot easier.\ I will try to fix reported issues as soon as possible, but I do this in my spare time, so I might not be able to do it immediately.

Installation

Options reference

scopes - array

Scopes to send when requesting an access token. Typically only used for OAuth2 flows.\ Possible options: array with strings Default: []

authType - string

The type of authorization for the refresh token request.\ Possible options: Credentials::AUTH_TYPE_BEARER, Credentials::AUTH_TYPE_BODY, Credentials::AUTH_TYPE_QUERY, Credentials::AUTH_TYPE_BASIC, Credentials::AUTH_TYPE_CUSTOM,\ Default: Credentials::AUTH_TYPE_BEARER (='Bearer')

grantType - string

Grant type for OAuth2 flows.\ Possible options: Credentials::GRANT_TYPE_CLIENT_CREDENTIALS, Credentials::GRANT_TYPE_PASSWORD_CREDENTIALS (authorization_code and implicit grants are not yet supported. See issue #3)\ Default: Credentials::GRANT_TYPE_CLIENT_CREDENTIALS (='client_credentials')

tokenType - string

How the access token should be applied to all subsequent requests.\ Possible options: AccessToken::TOKEN_TYPE_BEARER, AccessToken::TOKEN_TYPE_QUERY, AccessToken::TOKEN_TYPE_CUSTOM \ Default: AccessToken::TOKEN_TYPE_BEARER (='Bearer')

tokenName - string

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.\ Possible options: Any string\ Default: 'token'

expires - int|string|Closure|Carbon

This determines when the access token expires.\ Possible options: \ integer - for how long until expiry in seconds)\ 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.\ Closure - A closure that receives the refresh response and can return any other acceptable value (integer, string or Carbon object).\ Carbon - A Carbon object with the time of the expiry.\ Default: 3600

accessToken - string|Closure

This is where the access token can be found on the refresh response.\ Possible options:\ string - The key of the access token in the refresh response.\ Closure - A closure that receives the refresh response and should return the token as a string.\ Default: 'access_token'

tokenTypeCustomCallback - ?Closure

A callback for giving dull control of how the authentication should be applied. The closure receives the Http client and should return a new Http Client where the auth information has been appended.\ Possible options:\ Any closure that returns a Http Client (Illuminate\Http\Client\PendingRequest).\ Default: null

cacheKey - ?string

The cache key that should be used to save the access tokens. If left empty, it will be generated based on the refresh URL.\ Possible options:\ Default: null

cacheDriver - ?string

The cache driver/store that should be used for storing the access tokens. If left empty, the Laravel default will be used.\ Possible options:\ Default: null

Usage

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

Minimal example:

All parameters with default values:

For full type safety, you can also provide objects instead of arrays:

Customize with callbacks

You can also provide callbacks for expires, auth_type, and access_token to customize the behavior.

Custom auth for refreshing token:

For more examples, check out the Macro tests.

Integration tips

If you use the same token in multiple places, you can create the client only once and save it. For example:

to use it later like this:

You can also resolve it in the container if you want. In your service provider:

and then use it anywhere like this:


All versions of laravel-http-client-auth-helper with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/support Version ^10 || ^11
guzzlehttp/guzzle Version ^7.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 pelmered/laravel-http-client-auth-helper contains the following files

Loading the files please wait ....