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

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

nospi/oauth2-microsoft
======================

Microsoft OAuth 2.0 Client Provider for The PHP League OAuth2-Client

0.1.0(2y ago)01651MITPHP

Since Nov 30Pushed 2y agoCompare

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

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

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

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

[![Latest Version](https://camo.githubusercontent.com/8fd244beace58c2dd0e77522ad7bb0e94d9bb6b28baf82ee2542c46ee90be5f0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f73746576656e6d6167756972652f6f61757468322d6d6963726f736f66742e7376673f7374796c653d666c61742d737175617265)](https://github.com/stevenmaguire/oauth2-microsoft/releases)[![Build Status](https://camo.githubusercontent.com/f766960dc9c17656b2168849f2acab65bebeba7abe1b7f3789ace24363f5bc3b/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f73746576656e6d6167756972652f6f61757468322d6d6963726f736f66742f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/stevenmaguire/oauth2-microsoft)[![Coverage Status](https://camo.githubusercontent.com/4c6121325939da5f0737c8f7f4cb8d524035de52cb50d9e92ed7c5904dfd4c6c/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f73746576656e6d6167756972652f6f61757468322d6d6963726f736f66742e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/stevenmaguire/oauth2-microsoft/code-structure)[![Quality Score](https://camo.githubusercontent.com/f642e437d041b55c081420a8d34d4d11f05064adc250c5a966d4d8c2f65454de/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f73746576656e6d6167756972652f6f61757468322d6d6963726f736f66742e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/stevenmaguire/oauth2-microsoft)[![Total Downloads](https://camo.githubusercontent.com/c8ebf9b7fd8b81e7717b771297f301e410aa08e690aa79fb59d3200f9314eea2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73746576656e6d6167756972652f6f61757468322d6d6963726f736f66742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/stevenmaguire/oauth2-microsoft)[![Software License](https://camo.githubusercontent.com/a089878fd3a26621f2de6b4bb05fa799d3d315248ec477d3ad2988a9e5818fe2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f73746576656e6d6167756972652f6f61757468322d6d6963726f736f66742e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)

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

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

[](#installation)

To install, use composer:

```
composer require stevenmaguire/oauth2-microsoft

```

Usage
-----

[](#usage)

Usage is the same as The League's OAuth client, using `\Stevenmaguire\OAuth2\Client\Provider\Microsoft` as the provider.

### Authorization Code Flow

[](#authorization-code-flow)

```
$provider = new Stevenmaguire\OAuth2\Client\Provider\Microsoft([
    // Required
    'clientId'                  => '{microsoft-client-id}',
    'clientSecret'              => '{microsoft-client-secret}',
    'redirectUri'               => 'https://example.com/callback-url',
    // Optional
    'urlAuthorize'              => 'https://login.windows.net/common/oauth2/authorize',
    'urlAccessToken'            => 'https://login.windows.net/common/oauth2/token',
    'urlResourceOwnerDetails'   => 'https://outlook.office.com/api/v1.0/me'
]);

if (!isset($_GET['code'])) {

    // If we don't have an authorization code then get one
    $authUrl = $provider->getAuthorizationUrl();
    $_SESSION['oauth2state'] = $provider->getState();
    header('Location: '.$authUrl);
    exit;

// Check given state against previously stored one to mitigate CSRF attack
} elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) {

    unset($_SESSION['oauth2state']);
    exit('Invalid state');

} else {

    // Try to get an access token (using the authorization code grant)
    $token = $provider->getAccessToken('authorization_code', [
        'code' => $_GET['code']
    ]);

    // Optional: Now you have a token you can look up a users profile data
    try {

        // We got an access token, let's now get the user's details
        $user = $provider->getResourceOwner($token);

        // Use these details to create a new profile
        printf('Hello %s!', $user->getFirstname());

    } catch (Exception $e) {

        // Failed to get user details
        exit('Oh dear...');
    }

    // Use this to interact with an API on the users behalf
    echo $token->getToken();
}
```

#### Managing Scopes and State

[](#managing-scopes-and-state)

When creating your Microsoft authorization URL, you can specify the state and scopes your application may authorize.

```
$options = [
    'state' => 'OPTIONAL_CUSTOM_CONFIGURED_STATE',
    'scope' => ['wl.basic', 'wl.signin'] // array or string
];

$authorizationUrl = $provider->getAuthorizationUrl($options);
```

If neither are defined, the provider will utilize internal defaults.

At the time of authoring this documentation, the following scopes are available.

##### Core

[](#core)

- wl.basic
- wl.offline\_access
- wl.signin

##### Extended

[](#extended)

- wl.birthday
- wl.calendars
- wl.calendars\_update
- wl.contacts\_birthday
- wl.contacts\_create
- wl.contacts\_calendars
- wl.contacts\_photos
- wl.contacts\_skydrive
- wl.emails
- wl.events\_create
- wl.imap
- wl.phone\_numbers
- wl.photos
- wl.postal\_addresses
- wl.skydrive
- wl.skydrive\_update
- wl.work\_profile
- office.onenote\_create

Testing
-------

[](#testing)

```
$ ./vendor/bin/phpunit
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/stevenmaguire/oauth2-microsoft/blob/master/CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [Steven Maguire](https://github.com/stevenmaguire)
- [All Contributors](https://github.com/stevenmaguire/oauth2-microsoft/contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](https://github.com/stevenmaguire/oauth2-microsoft/blob/master/LICENSE) for more information.

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity33

Early-stage or recently created project

 Bus Factor1

Top contributor holds 96.8% of commits — single point of failure

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

Unknown

Total

1

Last Release

890d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/84da43f77f7c52dece33cb249c84a782aa089faeceb2febd0b95358bef16f41f?d=identicon)[nospi](/maintainers/nospi)

---

Top Contributors

[![stevenmaguire](https://avatars.githubusercontent.com/u/1851973?v=4)](https://github.com/stevenmaguire "stevenmaguire (30 commits)")[![nospi](https://avatars.githubusercontent.com/u/19985451?v=4)](https://github.com/nospi "nospi (1 commits)")

---

Tags

clientoauthoauth2microsoftauthorizationauthorisation

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[thenetworg/oauth2-azure

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

2509.6M47](/packages/thenetworg-oauth2-azure)[stevenmaguire/oauth2-keycloak

Keycloak OAuth 2.0 Client Provider for The PHP League OAuth2-Client

2275.9M27](/packages/stevenmaguire-oauth2-keycloak)[stevenmaguire/oauth2-microsoft

Microsoft OAuth 2.0 Client Provider for The PHP League OAuth2-Client

742.3M12](/packages/stevenmaguire-oauth2-microsoft)[patrickbussmann/oauth2-apple

Sign in with Apple OAuth 2.0 Client Provider for The PHP League OAuth2-Client

1132.5M6](/packages/patrickbussmann-oauth2-apple)[mollie/oauth2-mollie-php

Mollie Provider for OAuth 2.0 Client

251.7M1](/packages/mollie-oauth2-mollie-php)[omines/oauth2-gitlab

GitLab OAuth 2.0 Client Provider for The PHP League OAuth2-Client

36721.5k13](/packages/omines-oauth2-gitlab)

PHPackages © 2026

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