Skip to content

Instantly share code, notes, and snippets.

@megamorf
Created September 23, 2016 16:46
Show Gist options
  • Save megamorf/29c088028730b964168943e6e4484b72 to your computer and use it in GitHub Desktop.
Save megamorf/29c088028730b964168943e6e4484b72 to your computer and use it in GitHub Desktop.
Webrequest - Authorization
$headers = @{}
$headers.Add('Authorization', "Bearer $accesstoken")
Invoke-RestMethod -Headers $headers -Uri https://graph.microsoft.com/v1.0/me -Method Get
# Step 1. Create a username:password pair
$plaintextCredentials = "$($username):$($password)"
# Step 2. Encode the pair to Base64 string
$encodedCredentials = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($plaintextCredentials))
# Step 3. Form the header and add the Authorization attribute to it
$headers = @{}
$headers.Add('Authorization',"Basic $encodedCredentials")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment