Basic authentication with the GitHub Api using PowerShell
Basic auth basically expects that you send the credentials in an Authorization
header in the following form:
'Basic [base64("username:password")]'
In PowerShell that would translate to something like:
function Get-BasicAuthCreds { param([string]$Username,[string]$Password) $AuthString = "{0}:{1}" -f $Username,$Password $AuthBytes = [System.Text.Encoding]::Ascii.GetBytes($AuthString) return [Convert]::ToBase64String($AuthBytes)}
And now you can do:
$BasicCreds = Get-BasicAuthCreds -Username "Shaun" -Password "s3cr3t"Invoke-WebRequest -Uri $GitHubUri -Headers @{"Authorization"="Basic $BasicCreds"}