This sample demonstrates how to use Dev Proxy to improve your app security when calling Microsoft Graph API.
- Run
npm install
to install project dependencies - Run the setup script to create a Microsoft Entra app registration
- PowerShell
- Execute
.\scripts\setup.ps1
- Execute
- bash
- Execute
chmod +x ./scripts/setup.sh
to make the script an executable - Execute
./scripts/setup.sh
- Execute
- PowerShell
If you work on a large solution that uses many endpoints, it can be difficult to build the exact list of minimal permissions for your application.
To check for minimal permissions locally:
- Start the local web server,
npm start
- Start Dev Proxy,
devproxy --config-file .devproxy/minimal-permissions.json --urls-to-watch "https://graph.microsoft.com/*" --record
- Navigate to
http://localhost:3000
, login and wait for the table to be populated - Stop recording mode, press S
- Stop Dev Proxy, press Ctrl + C
The minimal scopes for the tracked requests are shown in the console output.
A common approach to security is to apply the principle of least privilege (PoLP). This principle applies to users, processes and programs.
To check your access token for excessive permissions locally:
- Start the local web server,
npm start
- Start Dev Proxy in recording mode,
devproxy --config-file .devproxy/excessive-permissions.json --urls-to-watch "https://graph.microsoft.com/*" --record
- Navigate to
http://localhost:3000
, login and wait for the table to be populated - Stop recording mode, press S
- Stop Dev Proxy, press Ctrl + C
- Stop the local web server, press Ctrl + C
The guidance is shown in the console output.
To fix the app permissions and apply the principle of least privilege:
- Run the fix script to update permissions and scopes
- PowerShell
- Execute
.\scripts\fix.ps1
- Execute
- bash
- Execute
chmod +x ./scripts/fix.sh
to make the script an executable - Execute
./scripts/fix.sh
- Execute
- PowerShell
The script will:
- Replace the
Group.ReadWrite.All
scope withTasks.Read
insrc\env.js
- Remove the service principal
- Create a new service principal
- Add the
Tasks.Read
delegated permission and grant admin consent - Remove the
Group.ReadWrite.All
delegated permission
To reset the app permissions to the original state:
- Run the reset script to update permissions and scopes
- PowerShell
- Execute
.\scripts\reset.ps1
- Execute
- bash
- Execute
chmod +x ./scripts/reset.sh
to make the script an executable - Execute
./scripts/reset.sh
- Execute
- PowerShell
The script will:
- Replace the
Tasks.Read
scope withGroup.ReadWrite.All
insrc\env.js
- Remove the service principal
- Create a new service principal
- Add the
Group.ReadWrite.All
delegated permission and grant admin consent - Remove the
Tasks.Read
delegated permission
This sample is created from the Sample Reference already available in the Microsoft 365 Dev Proxy Samples which is created and pubished by Waldek Mastykarz & Garry Trinder.
THIS CODE IS PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.