Created
April 29, 2015 06:29
-
-
Save haraldfianbakken/27787c3be40b975364f9 to your computer and use it in GitHub Desktop.
Sample code on how to post an xml / base64 encoded file as a SAMLResponse to a server (Saml assertion)
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
Add-Type -AssemblyName System.Web; | |
$samlFile = "C:\Tmp\Assertion.xml" | |
$serviceProviderUri = "http://MYAPP/Sso/Acs" | |
function Get-SamlPayload($file){ | |
$f = Get-ChildItem $file; | |
# If the file is an xml, content must be encoded. | |
if($f.Extension -match ".xml"){ | |
$payload = ([xml](Get-Content $file)).InnerXml; | |
$payload = [System.Convert]::ToBase64String($payload.ToCharArray()); | |
} else{ | |
$payload = Get-Content $file; | |
} | |
# Modify the payload, by encoding invalid characters to post. | |
$payload = $payload -replace "[+]" , "%2B" -replace "=" , "%3D"; | |
return $payload; | |
} | |
$data = ("SAMLResponse={0}" -f (Get-SamlPayload -file $samlFile)); | |
$headers = @{ | |
"Content-Type"= "application/x-www-form-urlencoded"; | |
"Accept"="text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"; | |
"Accept-Encoding"="gzip, deflate"; | |
"Accept-Language"="en-US,en;q=0.8,nb;q=0.6" | |
"Content-Length"=$data.Length; | |
}; | |
Invoke-WebRequest $serviceProviderUri -method "POST" -Body $data -Headers $headers; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment