Created
April 7, 2023 12:47
-
-
Save andyhuey/de85972ec0f6268034e5ce46b0278a07 to your computer and use it in GitHub Desktop.
Get the auth hdr and send it to the clipboard.
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
# get-auth-hdr-1.ps1 | |
# Get the auth hdr and send it to the clipboard. | |
# ajh 2023-04-06: new. | |
#Requires -Version 7 | |
#Requires -Modules @{ ModuleName="MSAL.PS"; ModuleVersion="4.0" } | |
# force TLS 1.2 | |
$TLS12Protocol = [System.Net.SecurityProtocolType] 'Tls12' | |
[System.Net.ServicePointManager]::SecurityProtocol = $TLS12Protocol | |
echo $null | clip # clear the clipboard. | |
$secrets = dotnet user-secrets list --json | ConvertFrom-Json | |
$clientId = $secrets.'AuthConfig:ClientId' | |
$clientSecret = $secrets.'AuthConfig:ClientSecret' | |
$secSecret = ConvertTo-SecureString $clientSecret -AsPlainText -Force | |
$appSettings = Get-Content appsettings.json | ConvertFrom-Json | |
$scope = $appSettings.AuthConfig.ResourceId | |
$authority = $appSettings.AuthConfig.Instance -f $appSettings.AuthConfig.TenantId | |
$msalToken = Get-MsalToken -ClientId $clientId -ClientSecret $secSecret -Scope $scope -Authority $authority | |
$authHdr = $msalToken.CreateAuthorizationHeader() | |
$fullAuthHdr = "Authorization: $($authHdr)" | |
$fullAuthHdr | clip | |
"auth header has been copied to the clipboard." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment