Created
March 28, 2019 20:40
-
-
Save ehrnst/9f3f60fb7139c315bcafb7f742319c95 to your computer and use it in GitHub Desktop.
Azure AD authentication against azure functions using a custom app.
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
# getting a token from login.microsoft.com | |
# scope here is my custom app ID which has a custom application role defined. | |
$tenantID = "tenant.onmicrosoft.com" | |
$myCustomAPPID = "customAppWithID/.default" | |
$ClientID = 'your client id' | |
$ClientKey = 'your client key' | |
$params = @{ | |
scope = $myCustomAPPID; | |
grant_type = 'client_credentials'; | |
client_id = $ClientId; | |
client_secret = $ClientKey; | |
} | |
$AADToken = Invoke-RestMethod -Method Post -Uri "https://login.microsoftonline.com/$tenantID/oauth2/v2.0/token" -Body $params | |
# Using the bearer token agains my azure functions uri | |
$functionsURI = "https://functionappurl.azurewebsites.net/api/HttpTrigger1?name=ehrnst" | |
$heacders = @{ | |
Authorization = 'Bearer ' + $AADToken.access_token | |
} | |
Invoke-RestMethod -Uri $functionsURI -Headers $heacders |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://adatum.no/?p=6514