PHPackages                             plai2010/php-oauth2 - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. plai2010/php-oauth2

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

plai2010/php-oauth2
===================

OAuth2 utilities for PHP.

v1.3(2y ago)0157↓100%1MITPHP

Since Jul 20Pushed 2y ago1 watchersCompare

[ Source](https://github.com/plai2010/php-oauth2)[ Packagist](https://packagist.org/packages/plai2010/php-oauth2)[ RSS](/packages/plai2010-php-oauth2/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (1)Versions (8)Used By (1)

OAuth2 Utilities for PHP
========================

[](#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](#online-example) 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](https://oauth2-client.thephpleague.com/), its `GenericProvider` in particular.

Installation
------------

[](#installation)

The package can be installed from [Packagist](https://packagist.org/):

```
$ composer require plai2010/php-oauth2
```

One may also clone the source repository from `Github`:

```
$ git clone https://github.com/plai2010/php-oauth2.git
$ cd php-oauth2
$ composer install
```

Example: Obtaining Access Token for Outlook SMTP
------------------------------------------------------------------------------------------

[](#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`:

```
