Skip to content

Instantly share code, notes, and snippets.

@Mikej81
Created January 4, 2023 20:18
Show Gist options
  • Save Mikej81/44ad2d5a71dea388abead7f5c25c242b to your computer and use it in GitHub Desktop.
Save Mikej81/44ad2d5a71dea388abead7f5c25c242b to your computer and use it in GitHub Desktop.
401 Error Page Example with configurable SAMLAuthRequest
<html>
<head>
<script src="https://cdn.jsdelivr.net/gh/dankogai/js-deflate/rawdeflate.js"></script>
</head>
<body>
<h1>SAMLAuthnRequest Test</h1>
<br />
To use, modify the following variables:
<ul>
<li>var consumer = window.location.href; //Service Provider</li>
<li>var destination = 'https://sso.domain.com/login'; //Identity Provider </li>
<li>var issuer = 'https://sso.domain.com'; //Identity Provider</li>
</ul>
Todo:
<ul>
<li>-what else?</li>
</ul>
<form id="login" method="POST">
<input type="hidden" id="SAMLRequest" name="SAMLRequest">
<button onclick="setAssertion()">Logon</button>
<script>
var consumer = window.location.href; //Service Provider
var destination = 'https://sso.domain.com/login'; //Identity Provider
var issuer = 'https://sso.domain.com'; //Identity Provider
var template = `
'<samlp:AuthnRequest xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" ID="" Version="2.0" ProviderName="XC SP" IssueInstant="2014-07-16T23:52:45Z"
Destination="${destination}" ProtocolBinding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
AssertionConsumerServiceURL="${consumer}">
<saml:Issuer>${issuer}</saml:Issuer>
<samlp:NameIDPolicy Format="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress" AllowCreate="true" />
<samlp:RequestedAuthnContext Comparison="exact">
<saml:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport</saml:AuthnContextClassRef>
</samlp:RequestedAuthnContext>
</samlp:AuthnRequest>'
`;
var deflatedTemplate = RawDeflate.deflate(template);
//var encodedTemplate = btoa(template);
var encodedTemplate = btoa(deflatedTemplate);
function setAssertion() {
document.getElementById("SAMLRequest").setAttribute('value', encodedTemplate);
document.getElementById("login").setAttribute('action', issuer);
}
</script>
</form>
</body>
</html>
@Mikej81
Copy link
Author

Mikej81 commented Jan 4, 2023

If !Authorization then error page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment