Created
November 20, 2018 00:34
-
-
Save gscales/6dfff3c1eef5d9f62fcb740a05f70253 to your computer and use it in GitHub Desktop.
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
function Get-TenantId { | |
param( | |
[Parameter(Position = 1, Mandatory = $false)] | |
[String]$DomainName | |
) | |
Begin { | |
$RequestURL = "https://login.windows.net/{0}/.well-known/openid-configuration" -f $DomainName | |
Add-Type -AssemblyName System.Net.Http | |
$handler = New-Object System.Net.Http.HttpClientHandler | |
$handler.CookieContainer = New-Object System.Net.CookieContainer | |
$handler.AllowAutoRedirect = $true; | |
$HttpClient = New-Object System.Net.Http.HttpClient($handler); | |
$Header = New-Object System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json") | |
$HttpClient.DefaultRequestHeaders.Accept.Add($Header); | |
$HttpClient.Timeout = New-Object System.TimeSpan(0, 0, 90); | |
$HttpClient.DefaultRequestHeaders.TransferEncodingChunked = $false | |
$Header = New-Object System.Net.Http.Headers.ProductInfoHeaderValue("Get-TenantId", "1.1") | |
$HttpClient.DefaultRequestHeaders.UserAgent.Add($Header); | |
$ClientResult = $HttpClient.GetAsync([Uri]$RequestURL) | |
$JsonResponse = ConvertFrom-Json $ClientResult.Result.Content.ReadAsStringAsync().Result | |
return $JsonResponse.authorization_endpoint | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment