diff --git a/modules/consent/lib/Auth/Process/Consent.php b/modules/consent/lib/Auth/Process/Consent.php
index d497d40302eccae491c64160dc33d71fe670f3c2..b3df73e8cffc559f5a924d62c462b6ca51a82c57 100644
--- a/modules/consent/lib/Auth/Process/Consent.php
+++ b/modules/consent/lib/Auth/Process/Consent.php
@@ -149,11 +149,15 @@ class sspmod_consent_Auth_Process_Consent extends SimpleSAML_Auth_ProcessingFilt
 		$session = SimpleSAML_Session::getInstance(); 
 		$metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
 
-		/* If the consent module is active on a bridge $session->getIdP() will contain
-		 * an entry id for the remote IdP. If $session->getIdP() is NULL, then the
+		/* If the consent module is active on a bridge $state['saml:sp:IdP'] will contain
+		 * an entry id for the remote IdP. If not, then the
 		 * consent module is active on a local IdP and nothing needs to be done.
 		 */
-		if($session->getIdP() != null) {
+		if(isset($state['saml:sp:IdP'])) {
+			$idpmeta = $metadata->getMetaData($state['saml:sp:IdP'], 'saml20-idp-remote');
+			$state['Source'] = $idpmeta;
+		} elseif($session->getIdP() !== NULL) {
+			/* For backwards compatibility. TODO: Remove in version 1.8. */
 			$idpmeta = $metadata->getMetaData($session->getIdP(), 'saml20-idp-remote');
 			$state['Source'] = $idpmeta;
 		}