Authenticate with and call the Microsoft Graph
Summary
Obtain a new access token for the Microsoft Graph and use it an HTTP request, or connect to the Graph to perform operations.
Scripts
- CLI for Microsoft 365 using PowerShell
- CLI for Microsoft 365 using Bash
- PnP PowerShell
- Microsoft Graph PowerShell
$token = m365 util accesstoken get --resource https://graph.microsoft.com --new
$me = Invoke-RestMethod -Uri https://graph.microsoft.com/v1.0/me -Headers @{"Authorization"="Bearer $token"}
$me
Check out the CLI for Microsoft 365 to learn more at: https://aka.ms/cli-m365
Source Credit
Sample first appeared on Authenticate with and call the Microsoft Graph
Contributors
Author(s) |
---|
Garry Trinder |
Paul Bullock |
Disclaimer
THESE SAMPLES ARE 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.