PHPackages                             joeystowe/ms-graph-api - 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. [API Development](/categories/api)
4. /
5. joeystowe/ms-graph-api

ActiveLibrary[API Development](/categories/api)

joeystowe/ms-graph-api
======================

Laravel MS Graph API

v1.0.2(1y ago)24.5k↓40.6%MITPHPPHP ^8.1

Since Jan 23Pushed 8mo ago1 watchersCompare

[ Source](https://github.com/jbstowe/ms-graph-api)[ Packagist](https://packagist.org/packages/joeystowe/ms-graph-api)[ Docs](https://github.com/joeystowe/ms-graph-api)[ RSS](/packages/joeystowe-ms-graph-api/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (4)Versions (9)Used By (0)

MS GRAPH API PLUGIN
===================

[](#ms-graph-api-plugin)

This adds helper methods to call the MS Graph API and installs a middleware/routes to implement MS Authentication

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

[](#installation)

You can install the package via composer:

```
composer require joeystowe/ms-graph-api:^1.0
```

Usage
-----

[](#usage)

### SSO Authentication

[](#sso-authentication)

---

The plugin installs a middleware ('ms-auth') and 2 routes (/auth/callback and /logout). To protect a route with authentication you must apply the middleware to the desired routes and set your env variables

#### Apply middleware example

[](#apply-middleware-example)

```
Route::get('/', function () {
    return view('welcome');
})->middleware('ms-auth');
```

Or use middleware groups

```
Route::middleware('ms-auth')->group(function () {
    Route::get('/admin/dashboard', 'AdminController@dashboard');
});
```

Caution

You can not add the middleware globally or in the web group because the auth callback method needs to be publicy accessible

#### Set you .env variables

[](#set-you-env-variables)

```
// services.php
...
'azure' => [
	'client_id' => env('AZURE_CLIENT_ID'),
	'client_secret' => env('AZURE_CLIENT_SECRET'),
	'tenant' => env('AZURE_TENANT_ID'),
	'redirect' => env('AZURE_REDIRECT_URI'),
],
...
```

```
// .env
...
AZURE_CLIENT_ID=
AZURE_CLIENT_SECRET=
AZURE_REDIRECT_URI=http://localhost:8080/auth/callback
AZURE_TENANT_ID=
...
```

#### Accessing the user

[](#accessing-the-user)

The ms-auth middleware sets the following **scoped** session values

```
session()->put('ms:user', (object)$user);
session()->put('ms:username', $user['bannerUsername']);
session()->put('ms:email', $user['email']);
session()->put('ms:principalName', $user['principalName']);
session()->put('ms:id', $user['id']);
session()->put('ms:session-token', $user['token']);
```

You can reference these directly or you can use the **LoggedInUser** helper class:

```
// Returns an object with the following properties set
Joeystowe\MsGraphApi\LoggedInUser::user();
{
  "id" => "1111-2222-33333-44444" //ms user id
  "name" => "John Doe" //Full Name
  "email" => "john.doe@eng.ua.edu"
  "principalName" => "jdoe@ua.edu"
  "bannerUsername" => "jdoe"
  "token" => "1111-2222-3333-4444" //ms session token
}

//Fetch users properties as an array
Joeystowe\MsGraphApi\LoggedInUser::userArray();

//Fetch users properties as a pre-filled User model
Joeystowe\MsGraphApi\LoggedInUser::userModel();

//Fetch a single user attribute (throws exception is property is not found)
Joeystowe\MsGraphApi\LoggedInUser::userAttribute('principalName')
//returns "jdoe@ua.edu"
```

#### Logging Out

[](#logging-out)

Simply hit the '/logout' route to log the user out. After logging out from MS the user will be redirected to a '/postLogout' page. Be sure to set your APP\_URL correctly so the "log back in" url will work correctly.

You will also need to publish the assets for the postLogout page to be fully functional:

```
php artisan vendor:publish --tag=assets --ansi --force
```

### Calling Graph API

[](#calling-graph-api)

---

The plugin also gives you helper methods to call the MS graph API

#### Logged In User Methods

[](#logged-in-user-methods)

##### Groups

[](#groups)

```
$user = Joeystowe\MsGraphApi\LoggedInUser::user();
//resolve instance of current user API
$graphApi = app(Joeystowe\MsGraphApi\MsGraphCurrentUserApi::class, ['token' => $user->token]);

//Get all user's groups, returns array of groups
$graphApi->groups()

//Check if a user is in a specific group, returns boolean
$graphApi->inGroup(groupId: $groupIdToCheck)
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Credits
-------

[](#credits)

- [Joey Stowe](https://github.com/joeystowe)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance48

Moderate activity, may be stable

Popularity25

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity56

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

Total

7

Last Release

600d ago

Major Versions

v0.1 → v1.02024-04-21

### Community

Maintainers

![](https://www.gravatar.com/avatar/c32ab7b9b9c8d8c9339f676cd289b42821f1e64c9ff0ebab94e889b9b861ec4e?d=identicon)[jbstowe](/maintainers/jbstowe)

![](https://www.gravatar.com/avatar/89dfdddade928628cbcae406861788b02cff2fa29d4ed01c773ab64e03d2ba43?d=identicon)[mbjonesua](/maintainers/mbjonesua)

---

Top Contributors

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

---

Tags

joeystowems-graph-api

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/joeystowe-ms-graph-api/health.svg)

```
[![Health](https://phpackages.com/badges/joeystowe-ms-graph-api/health.svg)](https://phpackages.com/packages/joeystowe-ms-graph-api)
```

###  Alternatives

[joselfonseca/lighthouse-graphql-passport-auth

Add GraphQL types and mutations for login and recover password functionalities

234769.9k1](/packages/joselfonseca-lighthouse-graphql-passport-auth)[revolution/laravel-bluesky

Bluesky(AT Protocol) for Laravel

4317.3k](/packages/revolution-laravel-bluesky)[revolution/laravel-line-sdk

LINE SDK for Laravel

2235.8k](/packages/revolution-laravel-line-sdk)[marshmallow/laravel-facebook-webhook

A package to retrieve Facebook Leads with webhooks &amp; Graph API in Laravel.

123.2k](/packages/marshmallow-laravel-facebook-webhook)

PHPackages © 2026

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