Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/machv/ps-oauth2-toolkit
Simple OAuth2 helper to interact with Azure AD
https://github.com/machv/ps-oauth2-toolkit
Last synced: 12 days ago
JSON representation
Simple OAuth2 helper to interact with Azure AD
- Host: GitHub
- URL: https://github.com/machv/ps-oauth2-toolkit
- Owner: machv
- Created: 2019-10-04T20:15:15.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-09-13T13:36:07.000Z (over 3 years ago)
- Last Synced: 2024-11-07T23:41:11.824Z (2 months ago)
- Language: PowerShell
- Size: 108 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Azure AD OAuth2 toolkit
This module provides some helper functions to work with Azure AD OAuth2 endpoint without the need to construct URL manually.
## Installation
The easiest way to use this module is to download it from PowerShell Gallery:
```powershell
Install-Module -Name Oauth2Toolkit
```## Supported Grant Type Flows
| OAuth 2 Flow | Function | Notes |
| ------------- | ------------- | ----- |
| Authorization Code Grant | `Invoke-CodeGrantFlow` | |
| Device Code | `Invoke-DeviceCodeFlow` | |
| Password | `Invoke-ResourceOwnerPasswordGrantFlow` | |
| On behalf of | `Invoke-OnBehalfOfFlow` | https://docs.microsoft.com/cs-cz/azure/active-directory/develop/v2-oauth2-on-behalf-of-flow |## Example use
Obtain access token for the application:
```powershell
$response = Invoke-CodeGrantFlow -RedirectUrl "http://localhost:8080/auth" -ClientId "" -ClientSecret "" -Tenant "tenant.onmicrosoft.com" -Resource "" -AlwaysPrompt $true
```And use the returned Access Token to get resource specific Access Tokens for multiple services on behalf of the user:
```powershell
$graphAuthenticationHeaders = Invoke-OnBehalfOfFlow -Tenant "tenant.onmicrosoft.com" -ClientId "" -ClientSecret "" -AccessToken $response.access_token -Resource "https://graph.microsoft.com" | ConvertTo-AuthorizationHeadersInvoke-RestMethod -Method Get -Uri "https://graph.microsoft.com/v1.0/me" -Headers $graphAuthenticationHeaders
```