PHPackages                             bybrand/oauth2-microsoft - 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. bybrand/oauth2-microsoft

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

bybrand/oauth2-microsoft
========================

Microsoft Provider for PHP League's OAuth 2.0 Client

v1.0.2(3mo ago)07MITPHP

Since Mar 19Pushed 3mo agoCompare

[ Source](https://github.com/bybrand/oauth2-microsoft)[ Packagist](https://packagist.org/packages/bybrand/oauth2-microsoft)[ RSS](/packages/bybrand-oauth2-microsoft/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (4)Versions (3)Used By (0)

Microsoft Provider for PHP OAuth 2.0 Client
===========================================

[](#microsoft-provider-for-php-oauth-20-client)

This package provides Microsoft OAuth 2.0 support (v2.0 endpoints) for the PHP League's [OAuth 2.0 Client](https://github.com/thephpleague/oauth2-client).

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

[](#installation)

```
composer require bybrand/oauth2-microsoft
```

Usage
-----

[](#usage)

```
use Bybrand\OAuth2\Client\Provider\Microsoft;
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;

$provider = new Microsoft([
    'clientId'     => 'your-client-id',
    'clientSecret' => 'your-client-secret',
    'redirectUri'  => 'your-redirect-uri',
    'tenant'       => 'common', // common | organizations | consumers | tenant-id
]);

$params = $_GET;

if (!isset($params['code']) || empty($params['code'])) {
    $authorizationUrl = $provider->getAuthorizationUrl();
    $_SESSION['oauth2state'] = $provider->getState();

    header('Location: ' . $authorizationUrl);
    exit;
}

if (empty($params['state']) || ($params['state'] !== $_SESSION['oauth2state'])) {
    unset($_SESSION['oauth2state']);
    exit('Invalid state');
}

try {
    $token = $provider->getAccessToken('authorization_code', [
        'code' => $params['code']
    ]);

    $user = $provider->getResourceOwner($token);

    $id = $user->getId();
    $name = $user->getName();
    $email = $user->getEmail();
} catch (IdentityProviderException $e) {
    // Handle token/user request errors.
}
```

License
-------

[](#license)

MIT.

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance82

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~4 days

Total

2

Last Release

91d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0db1c7d7836cb218fe710bb074fa076dad1961a92e31ccbf6e7528ab7a8d07cf?d=identicon)[bybrand](/maintainers/bybrand)

---

Tags

phpAuthenticationoauth2microsoftauthorizationazure

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/bybrand-oauth2-microsoft/health.svg)

```
[![Health](https://phpackages.com/badges/bybrand-oauth2-microsoft/health.svg)](https://phpackages.com/packages/bybrand-oauth2-microsoft)
```

###  Alternatives

[thenetworg/oauth2-azure

Azure Active Directory OAuth 2.0 Client Provider for The PHP League OAuth2-Client

24610.3M72](/packages/thenetworg-oauth2-azure)[andalisolutions/oauth2-anaf

Anaf OAuth 2.0 support for the PHP League's OAuth 2.0 Client

195.9k](/packages/andalisolutions-oauth2-anaf)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
