Created
May 2, 2023 14:22
-
-
Save JordanTheITGuy/2494a48138c64f02937e71765380fad2 to your computer and use it in GitHub Desktop.
Get-AzureAppToken
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$tenantId = '' ### Paste your tenant ID here | |
$appId = '' ### Paste your Application ID here | |
$appSecret = '' ### Paste your Application secret here | |
#NOTE: Build the auth response token to the Windows Security Center API (Basically establishing a logged in session) | |
$resourceAppIdUri = 'https://api.securitycenter.windows.com' | |
$oAuthUri = "https://login.windows.net/$TenantId/oauth2/token" | |
$authBody = [Ordered] @{ | |
resource = "$resourceAppIdUri" | |
client_id = "$appId" | |
client_secret = "$appSecret" | |
grant_type = 'client_credentials' | |
} | |
$authResponse = Invoke-RestMethod -Method Post -Uri $oAuthUri -Body $authBody -ErrorAction Stop | |
#NOTE: This returns your access token, and below we pull out the token that will be used as the authorization token going forward. | |
$token = $authResponse.access_token |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment