8000 GitHub - omega1119/m365-python
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

omega1119/m365-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Microsoft 365 Graph API - App Registration & Python Example

Overview

This project contains:

  • A PowerShell script (setup-appregistration.ps1) to automate Azure App Registration using Azure CLI.
  • A Jupyter Notebook (graph_api_example.ipynb) to authenticate and fetch Microsoft 365 Graph API data.

Prerequisites

Required Tools

Azure Requirements

  • Access to an Azure Subscription with permissions to create app registrations.
  • Global Admin or Application Administrator role to grant Graph API permissions.

Setup & Run the PowerShell Script

1. Configure Azure App Registration

  1. Open PowerShell and log in to Azure:

    ./setup-appregistration.ps1

    This will:

    • Register a new Azure AD App.
    • Create a Client Secret (recycling it if one exists).
    • Assign Graph API permissions (User.Read.All, Directory.Read.All).
    • Grant Admin Consent.
    • Create a Service Principal.
  2. Copy the output values:

    • App ID
    • Client Secret
    • Tenant ID
  3. A file called config.json will be created with these credentials for use in the Jupyter Notebook.


Run the Jupyter Notebook

1. Open graph_api_example.ipynb

  1. Ensure config.json exists in the working directory.
  2. Open the notebook and edit these variables:
    TENANT_ID = ""
    CLIENT_ID = ""
    CLIENT_SECRET = ""
    OR load them directly from config.json.
  3. Run the notebook to:
    • Authenticate using Microsoft 365 Graph API.
    • Fetch the number of users in the tenant.
    • Generate a pie chart showing user statistics.

Notes

  • The PowerShell script ensures credentials are not duplicated.
  • Ensure admin consent is granted for API permissions before running the Python script.
  • The Jupyter Notebook assumes at least 1 user is present in the tenant.

For troubleshooting, refer to:


Project Structure

m365-python/                                                             
                                                                       
├── graph_api_example.ipynb     # Jupyter Notebook with the Python example   
├── setup-appregistration.ps1   # PowerShell script for app registration setup 
├── requirements.txt            # List of Python dependencies                
└── README.md                   # Project documentation                        

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0