diff --git a/modules/saml/src/Auth/Source/SP.php b/modules/saml/src/Auth/Source/SP.php
index 9e0f5882d7ca901f77b289e412eec5c6a5b91ab5..f11afa9baf59ffa65a4b0babeaa56ea475e04d3a 100644
--- a/modules/saml/src/Auth/Source/SP.php
+++ b/modules/saml/src/Auth/Source/SP.php
@@ -81,6 +81,9 @@ class SP extends \SimpleSAML\Auth\Source
         // Call the parent constructor first, as required by the interface
         parent::__construct($info, $config);
 
+        /* For compatibility with code that assumes that $metadata->getString('entityid')
+         * gives the entity id. */
+        $config['entityid'] = $config['entityID'];
         $this->metadata = Configuration::loadFromArray(
             $config,
             'authsources[' . var_export($this->authId, true) . ']'
diff --git a/src/SimpleSAML/Metadata/MetaDataStorageHandlerFlatFile.php b/src/SimpleSAML/Metadata/MetaDataStorageHandlerFlatFile.php
index 042dfa477da4ffc8af2aeecbc41ba851226dd772..cac0b975d9099f868f3be450744466b14eed79ba 100644
--- a/src/SimpleSAML/Metadata/MetaDataStorageHandlerFlatFile.php
+++ b/src/SimpleSAML/Metadata/MetaDataStorageHandlerFlatFile.php
@@ -124,7 +124,7 @@ class MetaDataStorageHandlerFlatFile extends MetaDataStorageSource
 
         // add the entity id of an entry to each entry in the metadata
         foreach ($metadataSet as $entityId => &$entry) {
-            $entry['entityID'] = $entityId;
+            $entry['entityid'] = $entityId;
         }
 
         $this->cachedMetadata[$set] = $metadataSet;
diff --git a/src/SimpleSAML/Metadata/MetaDataStorageHandlerPdo.php b/src/SimpleSAML/Metadata/MetaDataStorageHandlerPdo.php
index c84408f25c337c1c03fb0620e231eb3db756b0fb..bfd4b1a6d3c0ed4fde7a8ac1895b5637ac1a9730 100644
--- a/src/SimpleSAML/Metadata/MetaDataStorageHandlerPdo.php
+++ b/src/SimpleSAML/Metadata/MetaDataStorageHandlerPdo.php
@@ -96,7 +96,7 @@ class MetaDataStorageHandlerPdo extends MetaDataStorageSource
                     throw new Error\Exception("Cannot decode metadata for entity '${d['entity_id']}'");
                 }
                 if (!array_key_exists('entityid', $data)) {
-                    $data['entityID'] = $d['entity_id'];
+                    $data['entityid'] = $d['entity_id'];
                 }
                 $metadata[$d['entity_id']] = $data;
             }
@@ -129,7 +129,7 @@ class MetaDataStorageHandlerPdo extends MetaDataStorageSource
         }
 
         foreach ($metadataSet as $entityId => &$entry) {
-            $entry['entityID'] = $entityId;
+            $entry['entityid'] = $entityId;
         }
 
         $this->cachedMetadata[$set] = $metadataSet;