diff --git a/lib/SAML2/AuthnRequest.php b/lib/SAML2/AuthnRequest.php
index 475afb87781a8fad36777f8ae93b18fe5a3c8fa9..a442dd64055d8afec36974f7b2f68a2074736670 100644
--- a/lib/SAML2/AuthnRequest.php
+++ b/lib/SAML2/AuthnRequest.php
@@ -271,18 +271,6 @@ class SAML2_AuthnRequest extends SAML2_Request {
 			$root->setAttribute('ProtocolBinding', $this->protocolBinding);
 		}
 
-		if (count($this->IDPList) > 0) {
-			$scoping = $this->document->createElementNS(SAML2_Const::NS_SAMLP, 'Scoping');
-			$idplist = $this->document->createElementNS(SAML2_Const::NS_SAMLP, 'IDPList');
-			foreach ($this->IDPList as $provider) {
-				$idpEntry = $this->document->createElementNS(SAML2_Const::NS_SAMLP, 'IDPEntry');
-				$idpEntry->setAttribute('ProviderID', $provider);
-				$idplist->appendChild($idpEntry);
-			}
-			$scoping->appendChild($idplist);
-			$root->appendChild($scoping);
-		}
-
 		if (!empty($this->nameIdPolicy)) {
 			$nameIdPolicy = $this->document->createElementNS(SAML2_Const::NS_SAMLP, 'NameIDPolicy');
 			if (array_key_exists('Format', $this->nameIdPolicy)) {
@@ -297,6 +285,18 @@ class SAML2_AuthnRequest extends SAML2_Request {
 			$root->appendChild($nameIdPolicy);
 		}
 
+		if (count($this->IDPList) > 0) {
+			$scoping = $this->document->createElementNS(SAML2_Const::NS_SAMLP, 'Scoping');
+			$idplist = $this->document->createElementNS(SAML2_Const::NS_SAMLP, 'IDPList');
+			foreach ($this->IDPList as $provider) {
+				$idpEntry = $this->document->createElementNS(SAML2_Const::NS_SAMLP, 'IDPEntry');
+				$idpEntry->setAttribute('ProviderID', $provider);
+				$idplist->appendChild($idpEntry);
+			}
+			$scoping->appendChild($idplist);
+			$root->appendChild($scoping);
+		}
+
 		return $root;
 	}