Last active
July 20, 2021 15:35
-
-
Save h4de5/ef390dd5c0f41af8d14b1c013a9ceef7 to your computer and use it in GitHub Desktop.
Use basic authentification, ignore invalid and self-signed certificates and parse the request result
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
token=$(curl --insecure --request GET \ | |
--url "https://localhost:1234/Token" \ | |
--header "$(echo Authorization: Basic $(echo -n 'username:password' | base64))") | |
# echo $token | |
# open browser | |
# xdg-open "https://localhost:1234/?token=" + $token | |
sensible-browser "https://localhost:1234/?token=" + $token |
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
$user = 'username' | |
$pass = 'password' | |
$url = 'https://localhost:1234/Token' | |
$pair = "$($user):$($pass)" | |
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair)) | |
$Headers = @{ | |
ContentType = "text/plain" | |
Authorization = "Basic $encodedCreds" | |
} | |
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 | |
if (-not ([System.Management.Automation.PSTypeName]'ServerCertificateValidationCallback').Type) | |
{ | |
$certCallback = @" | |
using System; | |
using System.Net; | |
using System.Net.Security; | |
using System.Security.Cryptography.X509Certificates; | |
public class ServerCertificateValidationCallback | |
{ | |
public static void Ignore() | |
{ | |
if(ServicePointManager.ServerCertificateValidationCallback ==null) | |
{ | |
ServicePointManager.ServerCertificateValidationCallback += | |
delegate | |
( | |
Object obj, | |
X509Certificate certificate, | |
X509Chain chain, | |
SslPolicyErrors errors | |
) | |
{ | |
return true; | |
}; | |
} | |
} | |
} | |
"@ | |
Add-Type $certCallback | |
} | |
[ServerCertificateValidationCallback]::Ignore() | |
$result = Invoke-WebRequest -Uri $url -Headers $Headers -Method Get | |
$result.Headers.'Content-Type text/plain; charset=utf-8' | |
$token = [System.Text.Encoding]::UTF8.GetString($result.Content) | |
# open browser | |
Start-Process ("https://localhost:1234/?token=" + $token) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment