diff --git a/modules/saml/lib/IdP/SAML2.php b/modules/saml/lib/IdP/SAML2.php
index 68b285fb0cb178604978c4fdedbe373787ce8418..2eb5e2feefb7667bf5fe44b7123b063000967d34 100644
--- a/modules/saml/lib/IdP/SAML2.php
+++ b/modules/saml/lib/IdP/SAML2.php
@@ -565,9 +565,13 @@ class sspmod_saml_IdP_SAML2 {
 
 		$a->setAuthnContext(SAML2_Const::AC_PASSWORD);
 
-		$session = SimpleSAML_Session::getInstance();
-
-		$a->setAuthnInstant($session->getAuthnInstant());
+		if (isset($state['AuthnInstant'])) {
+			$a->setAuthnInstant($state['AuthnInstant']);
+		} else {
+			/* For backwards compatibility. Remove in version 1.8. */
+			$session = SimpleSAML_Session::getInstance();
+			$a->setAuthnInstant($session->getAuthnInstant());
+		}
 
 		$sessionLifetime = $config->getInteger('session.duration', 8*60*60);
 		$a->setSessionNotOnOrAfter(time() + $sessionLifetime);