Download the PHP package plai2010/php-oauth2 without Composer

On this page you can find all versions of the php package plai2010/php-oauth2. 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 php-oauth2

OAuth2 Utilities for PHP

This is a utility package for handling OAuth2 in PHP applications. It allows obtaining OAuth2 access token through an authorization code grant with just a browser and a command shell running side by side; there is no need to set up a working web endpoint for the OAuth2 provider to call back.

On-line authorization flow with working redirect is also supported. See this section for how it may be set up in an Laravel application.

The use case for this package was SMTP XOAUTH2 authentication in a Laravel (10.x) application. A Laravel service provider is included.

This package depends on league/oauth2-client, its GenericProvider in particular.

Installation

The package can be installed from Packagist:

One may also clone the source repository from Github:

Example: Obtaining Access Token for Outlook SMTP

Let us say a web application has been registered in Micrsoft Azure AD:

* Application ID - 11111111-2222-3333-4444-567890abcdef
* Application secret - v8rstf8eVD5My89xDOTw8CoKG6rIw9dukIjHYzPU
* Redirect URI - http://localhost/example

For our purpose the redirect URI should not point to an actual web site. It can be any URL in proper format; just test with a browser to ake sure it yields a 404 error.

Create a PHP script, say outlook-oauth2.php:

To obtain an OAuth2 token for SMTP login (XOAUTH2), start an interactive PHP shell:

Obtain an authorization URL:

An URL like this is printed as the result (line breaks inserted):

Do not end the interactive PHP shell. Copy the URL into a browser and go through the steps to authorize access. At the end the browser will be redirected to an non-existing page with URL that matches the redirect URI. Go back to the the interactive PHP shell to process that URL:

The token can be saved to some storage (e.g. database) for use by an application. If the token has expiration and is refreshable, the application would request a refresh. This is illustrated as follows:

Provider Manager

An application may interact with multiple OAuth2 providers. For example, it may need authorization from Google to access files in Google Drive and from Microsoft to send email via Outlook SMTP. OAuth2Manager makes multiple OAuth2 providers available. For example,

Then to interact with Microsoft to obtain access token for SMTP login, one would do this:

Token Repository

It is up to an application to manage the storage of OAuth2 tokens. This package does includes TokenRepository and some implementation as a model, however. In this model, a token is identified by a two-part key: provider:usage. The two parts correspond to parameters of OAuth2Manager::get()(src/OAuth2Manager.php), so that a repository and refresh tokens as needed. The key scheme can be extended to suit an application. For example, to allow per-user OAuth2 tokens, provider:usage:user_id may suffice.

AbstractTokenRepository is an abstract implementation. Just provide tokenLoad() and tokenSave() methods.

Laravel Integration

This package includes a Laravel service provider that makes a singleton OAuth2Manager available two ways:

* Abstract 'oauth2' in the application container, i.e. `app('oauth2')`.
* Facade alias 'OAuth2', i.e. `OAuth2::`.

The configuration file is config/oauth2.php. It returns an associative array of provider configurations by names, like this:

There is no TokenRepository setup, but here is an example of making available as 'oauth2_tokens' a singleton DirectoryTokenRepository:

Example: Online Flow in Laravel Application

Let's say a Laravel application at example.com is using this package. One can add a route in routes/web.php for starting an authorization code grant flow:

Using Microsoft SMTP as in the Provider Manager example, request https://example.com/oauth2/authorize/microsoft/smtp would redirect to Microsoft's login.microsoftonline.com.

A route named oauth2.callback is assumed above for receiving authorization code. Here is what it would look like:

On Microsoft side, OAuth2 should be configured to allow redirect URI https://example.com/oauth2/callback/microsoft/smtp.


All versions of php-oauth2 with dependencies

PHP Build Version
Package Version
Requires league/oauth2-client Version ^2.7
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 plai2010/php-oauth2 contains the following files

Loading the files please wait ....