/** * Creates a SAML authentication request. * @param string $acsURL The URL to the SSO ACS * @param string $providerName The domain name of the identity requestor * @return string */ function createAuthnRequest($acsURL, $providerName) { $tml = file_get_contents('templates/AuthnRequestTemplate.xml'); $tml = str_replace('<PROVIDER_NAME>', $providerName, $tml); $tml = str_replace('<AUTHN_ID>', samlCreateId(), $tml); $tml = str_replace('<ACS_URL>', $acsURL, $tml); $tml = str_replace('<ISSUE_INSTANT>', samlGetDateTime(time()), $tml); return $tml; }
/** * Returns a SAML response with various elements filled in. * @param string $authenticatedUser The Google Apps username of the authenticated user * @param string $notBefore The ISO 8601 formatted date before which the response is invalid * @param string $notOnOrAfter The ISO 8601 formatted data after which the response is invalid * @param string $rsadsa 'rsa' if the response will be signed with RSA keys, 'dsa' for DSA keys * @param string $requestID The ID of the request we're responding to * @param string $destination The ACS URL that the response is submitted to * @return string XML SAML response. */ function createSamlResponse($authenticatedUser, $notBefore, $notOnOrAfter, $rsadsa, $requestID, $destination) { global $domainName; $samlResponse = file_get_contents('templates/SamlResponseTemplate.xml'); $samlResponse = str_replace('<USERNAME_STRING>', $authenticatedUser, $samlResponse); $samlResponse = str_replace('<RESPONSE_ID>', samlCreateId(), $samlResponse); $samlResponse = str_replace('<ISSUE_INSTANT>', samlGetDateTime(time()), $samlResponse); $samlResponse = str_replace('<AUTHN_INSTANT>', samlGetDateTime(time()), $samlResponse); $samlResponse = str_replace('<NOT_BEFORE>', $notBefore, $samlResponse); $samlResponse = str_replace('<NOT_ON_OR_AFTER>', $notOnOrAfter, $samlResponse); $samlResponse = str_replace('<ASSERTION_ID>', samlCreateId(), $samlResponse); $samlResponse = str_replace('<RSADSA>', strtolower($rsadsa), $samlResponse); $samlResponse = str_replace('<REQUEST_ID>', $requestID, $samlResponse); $samlResponse = str_replace('<DESTINATION>', $destination, $samlResponse); $samlResponse = str_replace('<ISSUER_DOMAIN>', $domainName, $samlResponse); return $samlResponse; }