Last active
May 21, 2020 15:29
-
-
Save fataltrace/64f5d9f6bede311dab5b6fd15dc03cae to your computer and use it in GitHub Desktop.
ADFS token
This file contains hidden or 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
| #!/usr/bin/env bash | |
| set -e | |
| PROG="$(basename "$0")" | |
| printUsage() { | |
| echo "Usage: $PROG ENTITY-ID ENDPOINT-URL" | |
| echo "" | |
| echo "Example:" | |
| echo " $PROG urn:someservice https://sp.example.org/mellon" | |
| echo "" | |
| } | |
| if [ "$#" -lt 2 ]; then | |
| printUsage | |
| exit 1 | |
| fi | |
| ENTITYID="$1" | |
| if [ -z "$ENTITYID" ]; then | |
| echo "$PROG: An entity ID is required." >&2 | |
| exit 1 | |
| fi | |
| BASEURL="$2" | |
| if [ -z "$BASEURL" ]; then | |
| echo "$PROG: The URL to the MellonEndpointPath is required." >&2 | |
| exit 1 | |
| fi | |
| if ! echo "$BASEURL" | grep -q '^https\?://'; then | |
| echo "$PROG: The URL must start with \"http://\" or \"https://\"." >&2 | |
| exit 1 | |
| fi | |
| HOST="$(echo "$BASEURL" | sed 's#^[a-z]*://\([^:/]*\).*#\1#')" | |
| BASEURL="$(echo "$BASEURL" | sed 's#/$##')" | |
| OUTFILE="token" | |
| CERT_FILE="coffee_cert.pem" | |
| echo "Output files:" | |
| echo "Metadata: $OUTFILE.xml" | |
| echo "Host: $HOST" | |
| echo | |
| echo "Endpoints:" | |
| echo "SingleLogoutService: $BASEURL/logout" | |
| echo "AssertionConsumerService: $BASEURL/postResponse" | |
| echo | |
| # No files should not be readable by the rest of the world. | |
| umask 0077 | |
| CERT="$(grep -v '^-----' "$CERT_FILE")" | |
| cat >"$OUTFILE.xml" <<EOF | |
| <EntityDescriptor entityID="$ENTITYID" xmlns="urn:oasis:names:tc:SAML:2.0:metadata" xmlns:ds="http://www.w3.org/2000/09/xmldsig#"> | |
| <SPSSODescriptor protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol"> | |
| <KeyDescriptor use="signing"> | |
| <ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#"> | |
| <ds:X509Data> | |
| <ds:X509Certificate>$CERT</ds:X509Certificate> | |
| </ds:X509Data> | |
| </ds:KeyInfo> | |
| </KeyDescriptor> | |
| <SingleLogoutService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect" Location="$BASEURL/logout"/> | |
| <AssertionConsumerService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" Location="$BASEURL/postResponse" index="0"/> | |
| </SPSSODescriptor> | |
| </EntityDescriptor> | |
| EOF | |
| umask 0777 | |
| chmod go+r "$OUTFILE.xml" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment