diff --git a/modules/saml/lib/Auth/Source/SP.php b/modules/saml/lib/Auth/Source/SP.php
index 2127746b010a4b0d442968f9ff3b417f7097e6c2..0f023943e4dbd77df13a24885ef4671901b8d08f 100644
--- a/modules/saml/lib/Auth/Source/SP.php
+++ b/modules/saml/lib/Auth/Source/SP.php
@@ -51,7 +51,7 @@ class sspmod_saml_Auth_Source_SP extends SimpleSAML_Auth_Source {
 		if (array_key_exists('entityId', $config)) {
 			$config['entityid'] = $config['entityId'];
 		} else {
-			$config['entityid'] = SimpleSAML_Module::getModuleURL('saml/sp/metadata.php/' . urlencode($this->authId));
+			$config['entityid'] = $this->getMetadataURL();
 		}
 
 		$this->metadata = SimpleSAML_Configuration::loadFromArray($config, 'authsources[' . var_export($this->authId, TRUE) . ']');
@@ -61,6 +61,17 @@ class sspmod_saml_Auth_Source_SP extends SimpleSAML_Auth_Source {
 	}
 
 
+	/**
+	 * Retrieve the URL to the metadata of this SP.
+	 *
+	 * @return string  The metadata URL.
+	 */
+	public function getMetadataURL() {
+
+		return SimpleSAML_Module::getModuleURL('saml/sp/metadata.php/' . urlencode($this->authId));
+	}
+
+
 	/**
 	 * Retrieve the entity id of this SP.
 	 *