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

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

socialiteproviders/microsoft
============================

Microsoft OAuth2 Provider for Laravel Socialite

4.9.1(1mo ago)326.1M↑12.6%17[1 issues](https://github.com/SocialiteProviders/Microsoft/issues)12MITPHPPHP ^8.0CI failing

Since Jan 5Pushed 1mo agoCompare

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

READMEChangelog (10)Dependencies (4)Versions (22)Used By (12)

Microsoft
=========

[](#microsoft)

```
composer require socialiteproviders/microsoft
```

Installation &amp; Basic Usage
------------------------------

[](#installation--basic-usage)

Please see the [Base Installation Guide](https://socialiteproviders.com/usage/), then follow the provider specific instructions below.

### Add configuration to `config/services.php`

[](#add-configuration-to-configservicesphp)

```
'microsoft' => [
  'client_id' => env('MICROSOFT_CLIENT_ID'),
  'client_secret' => env('MICROSOFT_CLIENT_SECRET'),
  'redirect' => env('MICROSOFT_REDIRECT_URI'),
  'proxy' => env('PROXY')  // Optional, will be used for all requests
],
```

### Add provider event listener

[](#add-provider-event-listener)

#### Laravel 11+

[](#laravel-11)

In Laravel 11, the default `EventServiceProvider` provider was removed. Instead, add the listener using the `listen` method on the `Event` facade, in your `AppServiceProvider` `boot` method.

- Note: You do not need to add anything for the built-in socialite providers unless you override them with your own providers.

```
Event::listen(function (\SocialiteProviders\Manager\SocialiteWasCalled $event) {
    $event->extendSocialite('microsoft', \SocialiteProviders\Microsoft\Provider::class);
});
```

Laravel 10 or below Configure the package's listener to listen for `SocialiteWasCalled` events. Add the event to your `listen[]` array in `app/Providers/EventServiceProvider`. See the [Base Installation Guide](https://socialiteproviders.com/usage/) for detailed instructions.

```
protected $listen = [
    \SocialiteProviders\Manager\SocialiteWasCalled::class => [
        // ... other providers
        \SocialiteProviders\Microsoft\MicrosoftExtendSocialite::class.'@handle',
    ],
];
```

### Usage

[](#usage)

You should now be able to use the provider like you would regularly use Socialite (assuming you have the facade installed):

```
return Socialite::driver('microsoft')->redirect();
```

Extended features
-----------------

[](#extended-features)

### ID token validation and key rollover

[](#id-token-validation-and-key-rollover)

When using the `openid` scope, Microsoft returns an `id_token` JWT. This provider validates the `id_token` signature and claims.

Microsoft (Entra ID / Azure AD) periodically rotates signing keys. During rollover there can be a short window where a token is signed with a new key that is not yet available from the published JWKS endpoints. To reduce intermittent login failures, the provider caches JWKS briefly and will refresh the JWKS and retry validation once when it encounters an unknown `kid`.

### Roles

[](#roles)

`Socialite::driver('microsoft')->user()->getRoles()` returns an array of strings containing the names of the Microsoft 365/Azure AD groups the authenticated user belongs to. You can use this information to assign users to application roles at login.

- ref. [Emit groups as role claims in Entra ID](https://learn.microsoft.com/en-us/entra/identity/hybrid/connect/how-to-connect-fed-group-claims)

### Tenant Details

[](#tenant-details)

You can also retrieve Tenant information at the same time as you retrieve users, this can be useful if you need to allow only your tenant/s or filter certain tenants.

To do this you first need to edit your `config/services.php` file and within your microsoft settings array include 'include\_tenant\_info' like the following:

```
'microsoft' => [
        'client_id' => env('MICROSOFT_CLIENT_ID'),
        'client_secret' => env('MICROSOFT_CLIENT_SECRET'),
        'redirect' => env('MICROSOFT_REDIRECT_URI'),
        'tenant' => 'common',
        'include_tenant_info' => true,
    ],
```

**NOTE: if you use `'tenant' => env('MICROSOFT_TENANT_ID')` then you should ensure that your .env file still uses 'common' as the tenant ID.**

The default tenant fields returned are:

- ID
- displayName
- city
- country
- countryLetterCode
- state
- street
- verifiedDomains

### Refresh token

[](#refresh-token)

By default Microsoft doesn't return a refresh token. But if you do need a refresh token you need to add the `offline_access` scope. Adding the scope is done on the `redirect` method as is described in the Laravel [docs](https://laravel.com/docs/master/socialite#access-scopes).

#### Tenant types

[](#tenant-types)

The [supported values (defined by MS Identity Platform)](https://learn.microsoft.com/en-au/azure/active-directory/develop/active-directory-v2-protocols#endpoints)for 'tenant' are listed below and can be used to control who can sign into the application.

- `common` - for both Microsoft accounts and work or school accounts (**most permissive**),
- `organizations` - for work or school accounts only,
- `consumers` - for Microsoft accounts only (*only services like Xbox, Teams for Life, or Outlook*),
- `tenant identifiers` - such as the tenant ID or domain name (**most restrictive**).

**Note:** when configuring the services.php microsoft entry with

- `tenant => 'common'`
- `include_tenant_info => true`

and attempting to login with a 'consumer' account, the user's tenant value will be null

e.g.

```
$user = Socialite::driver('microsoft')->user();
if ($user->tenant === null) {

    // do some consumer/public specific workflow

} else {

    // do your work / school tenant workflow
    Log::info(sprintf("Tenant found - %s", $user->tenant->displayName));

}

```

#### Additional tenant fields `tenant_fields`

[](#additional-tenant-fields-tenant_fields)

Any additional fields can be returned with the attribute names detailed [here](https://learn.microsoft.com/en-us/graph/api/resources/organization?view=graph-rest-1.0).

e.g. `'tenantType', 'technicalNotificationMails'` can be requested as such

```
    'microsoft' => [
        'client_id' => env('MICROSOFT_CLIENT_ID'),
        'client_secret' => env('MICROSOFT_CLIENT_SECRET'),
        'redirect' => env('MICROSOFT_REDIRECT_URI'),
        'tenant' => env('MICROSOFT_TENANT_ID', 'common'),
        'include_tenant_info' => true,
        'tenant_fields' => [ 'tenantType', 'technicalNotificationMails' ],
        'include_avatar' => true,
        'include_avatar_size' => '648x648',
    ],

```

###  Health Score

67

—

FairBetter than 100% of packages

Maintenance88

Actively maintained with recent releases

Popularity57

Moderate usage in the ecosystem

Community32

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor3

3 contributors hold 50%+ of commits

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 ~150 days

Recently: every ~65 days

Total

21

Last Release

54d ago

Major Versions

v1.1 → v3.0.02020-07-15

v3.0.0 → 4.0.02020-10-25

PHP version history (5 changes)v1.0.0PHP ^5.6 || ^7.0

4.0.0PHP ^7.2

4.1.0PHP ^7.2 || ^8.0

4.2.0PHP ^7.4 || ^8.0

4.2.3PHP ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/23558090?v=4)[Miguel Piedrafita](/maintainers/m1guelpf)[@m1guelpf](https://github.com/m1guelpf)

---

Top Contributors

[![lucasmichot](https://avatars.githubusercontent.com/u/513603?v=4)](https://github.com/lucasmichot "lucasmichot (17 commits)")[![atymic](https://avatars.githubusercontent.com/u/50683531?v=4)](https://github.com/atymic "atymic (11 commits)")[![allw1994](https://avatars.githubusercontent.com/u/9084938?v=4)](https://github.com/allw1994 "allw1994 (3 commits)")[![PaddingtonBrown](https://avatars.githubusercontent.com/u/8016852?v=4)](https://github.com/PaddingtonBrown "PaddingtonBrown (2 commits)")[![Jimbolino](https://avatars.githubusercontent.com/u/5860587?v=4)](https://github.com/Jimbolino "Jimbolino (2 commits)")[![faustbrian](https://avatars.githubusercontent.com/u/22145591?v=4)](https://github.com/faustbrian "faustbrian (1 commits)")[![Jannos-443](https://avatars.githubusercontent.com/u/77551365?v=4)](https://github.com/Jannos-443 "Jannos-443 (1 commits)")[![jortuck](https://avatars.githubusercontent.com/u/47679132?v=4)](https://github.com/jortuck "jortuck (1 commits)")[![kinekt4](https://avatars.githubusercontent.com/u/3781991?v=4)](https://github.com/kinekt4 "kinekt4 (1 commits)")[![laf](https://avatars.githubusercontent.com/u/3941142?v=4)](https://github.com/laf "laf (1 commits)")[![m1guelpf](https://avatars.githubusercontent.com/u/23558090?v=4)](https://github.com/m1guelpf "m1guelpf (1 commits)")[![madsem](https://avatars.githubusercontent.com/u/3166991?v=4)](https://github.com/madsem "madsem (1 commits)")[![maks-oleksyuk](https://avatars.githubusercontent.com/u/90793591?v=4)](https://github.com/maks-oleksyuk "maks-oleksyuk (1 commits)")[![mashedkeyboard](https://avatars.githubusercontent.com/u/16772519?v=4)](https://github.com/mashedkeyboard "mashedkeyboard (1 commits)")[![Max13](https://avatars.githubusercontent.com/u/531249?v=4)](https://github.com/Max13 "Max13 (1 commits)")[![nmiyazaki-chapleau](https://avatars.githubusercontent.com/u/104367522?v=4)](https://github.com/nmiyazaki-chapleau "nmiyazaki-chapleau (1 commits)")[![robchett](https://avatars.githubusercontent.com/u/5231691?v=4)](https://github.com/robchett "robchett (1 commits)")[![stephenstack](https://avatars.githubusercontent.com/u/7944609?v=4)](https://github.com/stephenstack "stephenstack (1 commits)")[![stidges](https://avatars.githubusercontent.com/u/4399967?v=4)](https://github.com/stidges "stidges (1 commits)")[![SuperDJ](https://avatars.githubusercontent.com/u/6484766?v=4)](https://github.com/SuperDJ "SuperDJ (1 commits)")

---

Tags

laraveloauthoauth1oauth2social-mediasocialitesocialite-providerslaravelprovideroauthsocialitemicrosoft

### Embed Badge

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

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

###  Alternatives

[socialiteproviders/microsoft-azure

Microsoft Azure OAuth2 Provider for Laravel Socialite

556.0M19](/packages/socialiteproviders-microsoft-azure)[socialiteproviders/apple

Apple OAuth2 Provider for Laravel Socialite

618.4M8](/packages/socialiteproviders-apple)[socialiteproviders/instagram

Instagram OAuth2 Provider for Laravel Socialite

421.9M5](/packages/socialiteproviders-instagram)[kovah/laravel-socialite-oidc

OpenID Connect OAuth2 Provider for Laravel Socialite

2073.7k](/packages/kovah-laravel-socialite-oidc)[socialiteproviders/kakao

Kakao OAuth2 Provider for Laravel Socialite

10484.7k4](/packages/socialiteproviders-kakao)

PHPackages © 2026

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