Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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-AuthorizationHeaders

Invoke-RestMethod -Method Get -Uri "https://graph.microsoft.com/v1.0/me" -Headers $graphAuthenticationHeaders
```