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

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

davicente/oauth2-microsoft
==========================

Microsoft OAuth 2.0 Client Provider for The PHP League OAuth2-Client (with Guzzle v5.3)

2.2.0(8y ago)08.9kMITPHP

Since Mar 21Pushed 8y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (4)Versions (8)Used By (0)

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). It uses Guzzle v5.3

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

32

—

LowBetter than 71% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 96.7% 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

Every ~134 days

Recently: every ~142 days

Total

7

Last Release

3260d ago

Major Versions

0.2.1 → 1.x-dev2015-11-12

1.x-dev → 2.0.02017-01-26

PHP version history (2 changes)0.1.0PHP &gt;=5.4.0

0.2.0PHP &gt;=5.5.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/919fd3b2e75a952f03e3a9bc6edecf386c6643ee355b5df9862d23798cba6861?d=identicon)[davicente](/maintainers/davicente)

---

Top Contributors

[![stevenmaguire](https://avatars.githubusercontent.com/u/1851973?v=4)](https://github.com/stevenmaguire "stevenmaguire (29 commits)")[![davicente](https://avatars.githubusercontent.com/u/752240?v=4)](https://github.com/davicente "davicente (1 commits)")

---

Tags

clientoauthoauth2microsoftauthorizationauthorisation

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[stevenmaguire/oauth2-microsoft

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

742.3M12](/packages/stevenmaguire-oauth2-microsoft)[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)
