Merge branch 'MDL-61826-master' of git://github.com/junpataleta/moodle
authorJun Pataleta <jun@moodle.com>
Wed, 6 Jun 2018 08:58:22 +0000 (16:58 +0800)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Wed, 6 Jun 2018 09:16:38 +0000 (11:16 +0200)
lib/classes/oauth2/api.php

index 72d4e97..6c39562 100644 (file)
@@ -86,10 +86,24 @@ class api {
         $issuer = new issuer(0, $record);
         $issuer->create();
 
+        // The Facebook API version.
+        $apiversion = '2.12';
+        // The Graph API URL.
+        $graphurl = 'https://graph.facebook.com/v' . $apiversion;
+        // User information fields that we want to fetch.
+        $infofields = [
+            'id',
+            'first_name',
+            'last_name',
+            'link',
+            'picture.type(large)',
+            'name',
+            'email',
+        ];
         $endpoints = [
-            'authorization_endpoint' => 'https://www.facebook.com/v2.12/dialog/oauth',
-            'token_endpoint' => 'https://graph.facebook.com/v2.12/oauth/access_token',
-            'userinfo_endpoint' => 'https://graph.facebook.com/v2.12/me?fields=id,first_name,last_name,link,picture,name,email'
+            'authorization_endpoint' => sprintf('https://www.facebook.com/v%s/dialog/oauth', $apiversion),
+            'token_endpoint' => $graphurl . '/oauth/access_token',
+            'userinfo_endpoint' => $graphurl . '/me?fields=' . implode(',', $infofields)
         ];
 
         foreach ($endpoints as $name => $url) {