Skip to main content

Lightweight python library for easily managing Azure AD (Entra ID) users and groups through the Graph API.

Project description

azure-graph-toolkit

Unit test Coverage Status Maintainability Deployment PyPI - Version

Downloads Downloads

Lightweight python library for easily managing Azure AD (Entra ID) users and groups through the Graph API.
Explore the docs (work in progress)»

· Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Roadmap
  4. Contact

About The Project

There are many great Azure libraries available on GitHub; however, I didn't find one that really suited my needs, so I created this one to simplify and automate daily tasks.

Features:

  • Add user to AAD group
  • Remove user from AAD group
  • Check if user is member of a group
  • List all user membership groups
  • Reset user password
  • Disable/enable user
  • Revoke user session tokens


Getting Started

Prerequisites

  1. Python >= 3.8
  2. Azure AD App Registration with the following role assigned:
Least privilege role Delegation type Description
GroupMember.ReadWrite.All Application To manage user membership groups.
GroupMember.Read.All Application List all the groups available.
User.ReadWrite.All, User Administrator role Application To change user password.
User.ManageIdentities.All, User.EnableDisableAccount.All Application To disable/enable user.
User.RevokeSessions.All Application To revoke user session tokens.

Installation

  1. Install azure-graph-toolkit library from PyPi
    pip install azure-graph-toolkit
    
  2. Profit 😁

(back to top)

Usage

Import library modules

from azure_graph_toolkit import graph_auth, graph_utils

App authentication and authorization. Once get the access token is possible to interact with Azure AD Graph API.

tenant_id = '<tenant Id>'
client_id = '<client (App) Id>'
client_secret = '<client secret>'

access_token = graph_auth.get_access_token(tenant_id, client_id, client_secret)

Add user to AAD group:

result = graph_utils.add_user_to_group('mario.rossi@domain.com', 'block-usb-group', access_token)

print(result)

Remove user from AAD group:

result = graph_utils.remove_user_from_group('mario.rossi@domain.com', 'block-usb-group', access_token)

print(result)

Disable user:

result = graph_utils.set_user_account_status('mario.rossi@domain.com', enable_account=False, access_token)

print(result)

Revoke user sessions:

result = graph_utils.user_revoke_sessions('mario.rossi@domain.com', access_token)

print(result)

Example Output

{'status_code': 204, 'message': 'Success. User mario.rossi@domain.com added to AAD group block-usb-group.'}
{'status_code': 404, 'message': 'No AAD group with a name containing \'block-usb-group\' was found. Please try another group name.'}

(back to top)

Roadmap

  • List user MFA status
  • List user's owned devices
  • List devices compliance status
  • Add device to group
  • Remove device from group
  • Create and delete users
  • Create and delete groups

(back to top)

Contact

Ivano Dibenedetto - @Linkedin - ivano.dibenedetto7@gmail.com

Project Link: https://github.com/Ivanodib/azure-graph-toolkit

(back to top)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

azure_graph_toolkit-1.1.1.tar.gz (23.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

azure_graph_toolkit-1.1.1-py3-none-any.whl (23.1 kB view details)

Uploaded Python 3

File details

Details for the file azure_graph_toolkit-1.1.1.tar.gz.

File metadata

  • Download URL: azure_graph_toolkit-1.1.1.tar.gz
  • Upload date:
  • Size: 23.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for azure_graph_toolkit-1.1.1.tar.gz
Algorithm Hash digest
SHA256 e302942060a09622c3745cf2db7c4f0cdcbbb217ae594c0b1b61ee999dc2b51d
MD5 a156502cdd8d60e7c2d23a26c18fe693
BLAKE2b-256 5937a35d14bafa7c41840a5c5189a37e1cf3d40a889165daede29470aa679f59

See more details on using hashes here.

File details

Details for the file azure_graph_toolkit-1.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for azure_graph_toolkit-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8a96b07fcb252b6b25a8b490ca7a126deea71471e1819288023a80d36d06158e
MD5 848b6a11161a049d895268aac82e4c85
BLAKE2b-256 b1219bcf844d1e674c14ffb0c535f594dd3056e67474de1916ec621dc8519aaf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page