Skip to content

Instantly share code, notes, and snippets.

@ehrnst
Created March 28, 2019 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ehrnst/9f3f60fb7139c315bcafb7f742319c95 to your computer and use it in GitHub Desktop.
Save ehrnst/9f3f60fb7139c315bcafb7f742319c95 to your computer and use it in GitHub Desktop.
Azure AD authentication against azure functions using a custom app.
# 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
@ehrnst
Copy link
Author

ehrnst commented Mar 28, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment