我一直在努力做basic authentication with the GitHub Api使用 PowerShell。以下不起作用:
> $cred = get-credential
# type username and password at prompt
> invoke-webrequest -uri https://api.github.com/user -credential $cred
Invoke-WebRequest : {
"message":"Requires authentication",
"documentation_url":"https://developer.github.com/v3"
}
我们如何使用 PowerShell 和 GitHub Api 进行基本身份验证?
最佳答案
基本身份验证基本上希望您在 Authorization
中发送凭据。标题格式如下:
'Basic [base64("username:password")]'
在 PowerShell 中,这将转换为:
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)
}
现在你可以这样做:
$BasicCreds = Get-BasicAuthCreds -Username "Shaun" -Password "s3cr3t"
Invoke-WebRequest -Uri $GitHubUri -Headers @{"Authorization"="Basic $BasicCreds"}
关于powershell - 使用 PowerShell 使用 GitHub Api 进行基本身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27969362/