<a id="readme-top"></a>
<!-- PROJECT LOGO -->
<br />
<!--<div align="center">
<a href="https://github.com/othneildrew/Best-README-Template">
<img src="images/logo.png" alt="Logo" width="80" height="80">
</a>-->
<h1 align="center">azure-graph-helper</h1>
<p align="center">
A Python library to manage Azure AD (Entra ID) user groups easily through Graph API.
<br />
<a href=https://github.com/Ivanodib/azure-graph-helper><strong>Explore the docs (work in progress)»</strong></a>
<br />
<br />
·
<a href="https://github.com/Ivanodib/azure-graph-helper/issues">Report Bug</a>
·
<a href="https://github.com/Ivanodib/azure-graph-helper/issues">Request Feature</a>
</p>
</div>
<!-- TABLE OF CONTENTS -->
<details>
<summary>Table of Contents</summary>
<ol>
<li>
<a href="#about-the-project">About The Project</a>
<ul>
<li><a href="#built-with">Built With</a></li>
</ul>
</li>
<li>
<a href="#getting-started">Getting Started</a>
<ul>
<li><a href="#prerequisites">Prerequisites</a></li>
<li><a href="#installation">Installation</a></li>
</ul>
</li>
<li><a href="#usage">Usage</a></li>
<li><a href="#roadmap">Roadmap</a></li>
<li><a href="#contributing">Contributing</a></li>
<li><a href="#license">License</a></li>
<li><a href="#contact">Contact</a></li>
<li><a href="#acknowledgments">Acknowledgments</a></li>
</ol>
</details>
<!-- ABOUT THE PROJECT -->
## 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 sysadmin tasks.
<!-- Here's why:
* Automate Sysadmin daily task
* Get user and groups informations. -->
<br>
<br>
<!-- GETTING STARTED -->
## Getting Started
### Prerequisites
1. Python >= 3.6
2. Azure AD App Registration with the following role assigned *(App delegation)*:
| Least privilege role | Type | Description |
| --- | --- | --- |
| `GroupMember.ReadWrite.All` | Application | To manage user membership groups. |
| `GroupMember.Read.All` | Application | List all the groups available, excluding dynamic distribution groups. |
| `User.Read.All` | Application | To get user informations. |
<br>
### Installation
1. Install azure-graph-helper library from PyPi
```sh
pip install azure-graph-helper
```
2. Profit :)
<p align="right">(<a href="#readme-top">back to top</a>)</p>
<!-- USAGE EXAMPLES -->
## Usage
Import library modules
```python
from azure_graph_helper import graph_auth, graph_utils
```
App authentication and authorization. Once get the access token is possible to interact with Azure AD Graph API.
```python
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)
```
<br>
**Add user to AAD group:**
```python
result = graph_utils.add_user_to_group('mario.rossi@domain.com',
'block-usb-group',
access_token)
print(result)
```
<br>
**Remove user from AAD group:**
```python
result = graph_utils.remove_user_from_group('mario.rossi@domain.com',
'block-usb-group',
access_token)
print(result)
```
<br>
**Error handling**<br>
Verify 'error' key presence in JSON response:
```python
result = graph_utils.remove_user_from_group('mario.rossi@domain.com',
'block-usb-group',
access_token)
if 'error' in result:
doSomething()
```
<br>
Example Output
```python
{'status_code': 204, 'message': 'Success. User mario.rossi@domain.com added to AAD group block-usb-group.'}
```
```python
{'status_code': 200, 'error': 'No AAD group name that contains block-usb-group found. Try another name.'}
```
<!--_For more examples, please refer to the [Documentation](https://example.com)_ -->
<p align="right">(<a href="#readme-top">back to top</a>)</p>
<!-- ROADMAP -->
## Roadmap
- [ ] Add orchestrator to change user membership temporarily
- [ ] Add module to manage user credentials
- [ ] Add module to manage Entra ID registered devices
- [ ] Add module to manage Intune MDM joined devices
<!-- See the [open issues](https://github.com/othneildrew/Best-README-Template/issues) for a full list of proposed features (and known issues). -->
<p align="right">(<a href="#readme-top">back to top</a>)</p>
<!-- CONTRIBUTING -->
## Contributing
Any contributions you make are **greatly appreciated**.
<br>
<!-- CONTACT -->
## Contact
Ivano Dibenedetto - [@Linkedin](https://www.linkedin.com/in/ivano-dibenedetto-b526ab188/) - ivano.dibenedetto7@gmail.com
Project Link: [https://github.com/Ivanodib/azure-graph-helper](https://github.com/Ivanodib/azure-graph-helper)
<p align="right">(<a href="#readme-top">back to top</a>)</p>
Raw data
{
"_id": null,
"home_page": "https://github.com/Ivanodib/azure-graph-helper",
"name": "azure-graph-helper",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": null,
"author": "Ivano Dibenedetto",
"author_email": "ivano.dibenedetto7@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/ca/4b/a95355e89a683e106caecf307e7440ae7941200f4ac8da1983366fc61e00/azure-graph-helper-1.0.1.2.tar.gz",
"platform": null,
"description": "\r\n\r\n<a id=\"readme-top\"></a>\r\n\r\n\r\n\r\n<!-- PROJECT LOGO -->\r\n<br />\r\n<!--<div align=\"center\">\r\n <a href=\"https://github.com/othneildrew/Best-README-Template\">\r\n <img src=\"images/logo.png\" alt=\"Logo\" width=\"80\" height=\"80\">\r\n </a>-->\r\n\r\n <h1 align=\"center\">azure-graph-helper</h1>\r\n\r\n <p align=\"center\">\r\n A Python library to manage Azure AD (Entra ID) user groups easily through Graph API.\r\n <br />\r\n <a href=https://github.com/Ivanodib/azure-graph-helper><strong>Explore the docs (work in progress)\u00bb</strong></a>\r\n <br />\r\n <br />\r\n \u00b7\r\n <a href=\"https://github.com/Ivanodib/azure-graph-helper/issues\">Report Bug</a>\r\n \u00b7\r\n <a href=\"https://github.com/Ivanodib/azure-graph-helper/issues\">Request Feature</a>\r\n </p>\r\n</div>\r\n\r\n\r\n\r\n<!-- TABLE OF CONTENTS -->\r\n<details>\r\n <summary>Table of Contents</summary>\r\n <ol>\r\n <li>\r\n <a href=\"#about-the-project\">About The Project</a>\r\n <ul>\r\n <li><a href=\"#built-with\">Built With</a></li>\r\n </ul>\r\n </li>\r\n <li>\r\n <a href=\"#getting-started\">Getting Started</a>\r\n <ul>\r\n <li><a href=\"#prerequisites\">Prerequisites</a></li>\r\n <li><a href=\"#installation\">Installation</a></li>\r\n </ul>\r\n </li>\r\n <li><a href=\"#usage\">Usage</a></li>\r\n <li><a href=\"#roadmap\">Roadmap</a></li>\r\n <li><a href=\"#contributing\">Contributing</a></li>\r\n <li><a href=\"#license\">License</a></li>\r\n <li><a href=\"#contact\">Contact</a></li>\r\n <li><a href=\"#acknowledgments\">Acknowledgments</a></li>\r\n </ol>\r\n</details>\r\n\r\n\r\n\r\n<!-- ABOUT THE PROJECT -->\r\n## About The Project\r\nThere 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 sysadmin tasks.\r\n\r\n<!-- Here's why:\r\n* Automate Sysadmin daily task\r\n* Get user and groups informations. -->\r\n\r\n<br>\r\n<br>\r\n\r\n\r\n<!-- GETTING STARTED -->\r\n## Getting Started\r\n\r\n\r\n### Prerequisites\r\n\r\n1. Python >= 3.6\r\n2. Azure AD App Registration with the following role assigned *(App delegation)*:\r\n\r\n\r\n| Least privilege role | Type | Description |\r\n| --- | --- | --- |\r\n| `GroupMember.ReadWrite.All` | Application | To manage user membership groups. |\r\n| `GroupMember.Read.All` | Application | List all the groups available, excluding dynamic distribution groups. |\r\n| `User.Read.All` | Application | To get user informations. |\r\n\r\n<br>\r\n\r\n### Installation\r\n\r\n1. Install azure-graph-helper library from PyPi \r\n ```sh\r\n pip install azure-graph-helper\r\n ```\r\n2. Profit :)\r\n\r\n<p align=\"right\">(<a href=\"#readme-top\">back to top</a>)</p>\r\n\r\n\r\n\r\n<!-- USAGE EXAMPLES -->\r\n## Usage\r\n\r\nImport library modules\r\n\r\n```python\r\n from azure_graph_helper import graph_auth, graph_utils\r\n ```\r\n\r\nApp authentication and authorization. Once get the access token is possible to interact with Azure AD Graph API.\r\n```python\r\n\r\n tenant_id = '<tenant Id>'\r\n client_id = '<client (App) Id>'\r\n client_secret = '<client secret>'\r\n\r\n access_token = graph_auth.get_access_token(tenant_id, client_id, client_secret)\r\n ```\r\n\r\n<br>\r\n\r\n\r\n**Add user to AAD group:**\r\n```python\r\n\r\n result = graph_utils.add_user_to_group('mario.rossi@domain.com',\r\n 'block-usb-group',\r\n access_token)\r\n print(result)\r\n\r\n\r\n ```\r\n\r\n<br>\r\n\r\n **Remove user from AAD group:**\r\n```python\r\n\r\n result = graph_utils.remove_user_from_group('mario.rossi@domain.com',\r\n 'block-usb-group',\r\n access_token)\r\n print(result)\r\n ```\r\n <br>\r\n\r\n **Error handling**<br>\r\n Verify 'error' key presence in JSON response: \r\n```python\r\n\r\n result = graph_utils.remove_user_from_group('mario.rossi@domain.com',\r\n 'block-usb-group',\r\n access_token)\r\n\r\n if 'error' in result:\r\n doSomething()\r\n \r\n ```\r\n<br>\r\n\r\n Example Output\r\n ```python\r\n {'status_code': 204, 'message': 'Success. User mario.rossi@domain.com added to AAD group block-usb-group.'}\r\n \r\n ```\r\n ```python\r\n {'status_code': 200, 'error': 'No AAD group name that contains block-usb-group found. Try another name.'}\r\n ```\r\n\r\n\r\n<!--_For more examples, please refer to the [Documentation](https://example.com)_ -->\r\n\r\n<p align=\"right\">(<a href=\"#readme-top\">back to top</a>)</p>\r\n\r\n\r\n\r\n<!-- ROADMAP -->\r\n## Roadmap\r\n\r\n- [ ] Add orchestrator to change user membership temporarily\r\n- [ ] Add module to manage user credentials\r\n- [ ] Add module to manage Entra ID registered devices\r\n- [ ] Add module to manage Intune MDM joined devices\r\n\r\n<!-- See the [open issues](https://github.com/othneildrew/Best-README-Template/issues) for a full list of proposed features (and known issues). -->\r\n\r\n<p align=\"right\">(<a href=\"#readme-top\">back to top</a>)</p>\r\n\r\n\r\n<!-- CONTRIBUTING -->\r\n## Contributing\r\nAny contributions you make are **greatly appreciated**.\r\n\r\n<br>\r\n\r\n\r\n\r\n<!-- CONTACT -->\r\n## Contact\r\nIvano Dibenedetto - [@Linkedin](https://www.linkedin.com/in/ivano-dibenedetto-b526ab188/) - ivano.dibenedetto7@gmail.com\r\n\r\nProject Link: [https://github.com/Ivanodib/azure-graph-helper](https://github.com/Ivanodib/azure-graph-helper)\r\n\r\n<p align=\"right\">(<a href=\"#readme-top\">back to top</a>)</p>\r\n",
"bugtrack_url": null,
"license": null,
"summary": "Python library to manage Azure AD (Entra ID) user groups easily through Graph API.",
"version": "1.0.1.2",
"project_urls": {
"Homepage": "https://github.com/Ivanodib/azure-graph-helper"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "7e3db90a66bfce37a6371baf59934f160b348331badf46ff15b10c71666c8438",
"md5": "858166fc3802aff4c968d4f4c376e6c1",
"sha256": "cdc60a40d6f9d71728e5641f38d08a637b978d18a99c6eebe34eca8b2290de94"
},
"downloads": -1,
"filename": "azure_graph_helper-1.0.1.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "858166fc3802aff4c968d4f4c376e6c1",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 18700,
"upload_time": "2024-08-06T15:30:03",
"upload_time_iso_8601": "2024-08-06T15:30:03.607749Z",
"url": "https://files.pythonhosted.org/packages/7e/3d/b90a66bfce37a6371baf59934f160b348331badf46ff15b10c71666c8438/azure_graph_helper-1.0.1.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "ca4ba95355e89a683e106caecf307e7440ae7941200f4ac8da1983366fc61e00",
"md5": "7ec5a00211a7037947dec6d903d70e54",
"sha256": "f5633f7a781ac53adbc839fd5672e87078e590e77bbc22f03f059f42003b59e6"
},
"downloads": -1,
"filename": "azure-graph-helper-1.0.1.2.tar.gz",
"has_sig": false,
"md5_digest": "7ec5a00211a7037947dec6d903d70e54",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 17814,
"upload_time": "2024-08-06T15:30:05",
"upload_time_iso_8601": "2024-08-06T15:30:05.354295Z",
"url": "https://files.pythonhosted.org/packages/ca/4b/a95355e89a683e106caecf307e7440ae7941200f4ac8da1983366fc61e00/azure-graph-helper-1.0.1.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-06 15:30:05",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Ivanodib",
"github_project": "azure-graph-helper",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "azure-graph-helper"
}