PHPackages                             singingfox/o365auth - 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. singingfox/o365auth

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

singingfox/o365auth
===================

0.1.1(7y ago)020PHP

Since May 5Pushed 7y agoCompare

[ Source](https://github.com/singingfox/o365auth)[ Packagist](https://packagist.org/packages/singingfox/o365auth)[ RSS](/packages/singingfox-o365auth/feed)WikiDiscussions master Synced 3d ago

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

Office 365 PHP Auth
===================

[](#office-365-php-auth)

This package adds authenticate against Office 365 to a Laravel application.

The package is largely based on program logic from [`microsoftgraph/php-connect-sample`](https://github.com/microsoftgraph/php-connect-sample), but aimed to easier integration with Laravel 5, and utilized more Laravel native things.

Expected Behaviors
------------------

[](#expected-behaviors)

- Failed authentication of an Office 365 account won't be granted access -- 500 error
- Successful authentication of an Office 365 account that doesn't belong to the specified domain won't be granted access -- 404 error
- Upon a successful authentication with an Office 365 account that is on the specified domain, user is redirected to the previous page, or to site root URL.
- If the successfully authenticated user is NOT in the system, the user would be added
- New user or existing user, if successfully authenticated, will be able to bypass email verification (verification flag will be set manually)

Installation and essential configurations
-----------------------------------------

[](#installation-and-essential-configurations)

### Install package with Composer

[](#install-package-with-composer)

**(NOTE: packagist not updated yet, the following may not work)**

First, run `composer require singingfox/o365auth` under Laraval application root directory.

Add the following to `composer.json`

`Singingfox\\O365Auth\\": "vendor/singingfox/o365auth/src`

Add the following to `config/app.php`

`Singingfox\O365Auth\O365AuthServiceProvider::class,`

Run

`composer dump-autoload`

Alternatively, add then following to `composer.json` then run `composer update`

```
"required": [
    ...
    "singingfox/o365auth": "*"
],

```

#### Dependencies

[](#dependencies)

When installing this package, the following packages and their dependencies are going to be pulled in as well.

```
"league/oauth2-client": "^2.3.*",
"microsoft/microsoft-graph": "^1.3.*"

```

### Configurations

[](#configurations)

#### Office 365 parameters needed in Laravel .env

[](#office-365-parameters-needed-in-laravel-env)

Add the following to .env file

```
O365_DOMAIN=ALLOWED-EMAIL-DOMAIN-NAME
O365_CLIENT_ID=YOUR-APPLICATION-ID-OR-CLIENT-ID-IN-CREATED-MICROSOFT-APPLICATION
O365_CLIENT_SECRET=YOUR-CLIENT-SECRETE-OR-CLIENT-PASSWORD-IN-CREATED-MICROSOFT-APPLICATION
# This needs to be the full URL (https)
O365_REDIRECT_URL=YOUR-REDIRECT-URL-IN-CREATED-MICROSOFT-APPLICATION

```

If not specified, a successful authentication will attempt to redirect application to the URL immediately prior to the authentication, or fall back to web root "/".

#### Display specific errors

[](#display-specific-errors)

Add a new view `resources/views/errors/500.blade.php`. The content could be as simple as

```
{{ $exception->getMessage() }}
```

This is optional, but if done, specific error message from this package, could be displayed. Otherwise, the following generic error message will be displayed for all errors:

`Whoops, looks like something went wrong.`

What to do after authentication
-------------------------------

[](#what-to-do-after-authentication)

At this time, the built-in program logic try to

The following is a sample of what can be done after successful authentication:

1. Retrieve `access_token` as stored in session
2. Initialize a `Graph` object, and assign the token to it
3. Now we should be able to call all kinds of Graph API endpoints and do whatever we need to do
4. Optionally, `O365_AFTER_AUTH_URL` can be specified in `.env` under Laraval application root, then a successful authentication process would be followed by some immediate actions, such as setting authenticated user locally, etc. The following sample route doesn't really do that. It only illustrates how to get a piece of user info -- email.

```
Route::get("/o365-user/email", function () {
    if (session_status() == PHP_SESSION_NONE)
        session_start();

    $graph = new \Microsoft\Graph\Graph();
    $graph->setAccessToken($_SESSION['access_token']);

    $me = $graph->createRequest("get", "/me")
        ->setReturnType(\Microsoft\Graph\Model\User::class)
        ->execute();

    return $me->getMail();
});
```

This authentication process can also be used to register new users that allows for access.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~132 days

Total

2

Last Release

2799d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7c495e608c2c7468b4a72144c9f6044029ffbb86c9b34aa70acda7fdddc1dac7?d=identicon)[singingfox](/maintainers/singingfox)

---

Top Contributors

[![singingfox](https://avatars.githubusercontent.com/u/34545721?v=4)](https://github.com/singingfox "singingfox (2 commits)")

### Embed Badge

![Health badge](/badges/singingfox-o365auth/health.svg)

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

###  Alternatives

[league/oauth2-google

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

41721.2M118](/packages/league-oauth2-google)[knpuniversity/oauth2-client-bundle

Integration with league/oauth2-client to provide services

83416.7M61](/packages/knpuniversity-oauth2-client-bundle)[thenetworg/oauth2-azure

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

2509.6M48](/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)[patrickbussmann/oauth2-apple

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

1132.5M6](/packages/patrickbussmann-oauth2-apple)[microsoft/kiota-authentication-phpleague

Authentication provider for Kiota using the PHP League OAuth 2.0 client to authenticate against the Microsoft Identity platform

153.2M7](/packages/microsoft-kiota-authentication-phpleague)

PHPackages © 2026

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