Subversion Repositories oidplus

Rev

Rev 1050 | Rev 1116 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. /*
  4.  * OIDplus 2.0
  5.  * Copyright 2019 - 2023 Daniel Marschall, ViaThinkSoft
  6.  *
  7.  * Licensed under the Apache License, Version 2.0 (the "License");
  8.  * you may not use this file except in compliance with the License.
  9.  * You may obtain a copy of the License at
  10.  *
  11.  *     http://www.apache.org/licenses/LICENSE-2.0
  12.  *
  13.  * Unless required by applicable law or agreed to in writing, software
  14.  * distributed under the License is distributed on an "AS IS" BASIS,
  15.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16.  * See the License for the specific language governing permissions and
  17.  * limitations under the License.
  18.  */
  19.  
  20. namespace ViaThinkSoft\OIDplus;
  21.  
  22. // phpcs:disable PSR1.Files.SideEffects
  23. \defined('INSIDE_OIDPLUS') or die;
  24. // phpcs:enable PSR1.Files.SideEffects
  25.  
  26. class OIDplusPagePublicLoginFacebook extends OIDplusPagePluginPublic {
  27.  
  28.         public function action($actionID, $params) {
  29.                 throw new OIDplusException(_L('Unknown action ID'));
  30.         }
  31.  
  32.         public function init($html=true) {
  33.                 // Nothing
  34.         }
  35.  
  36.         public function gui($id, &$out, &$handled) {
  37.                 if ($id === 'oidplus:login_facebook') {
  38.                         $handled = true;
  39.                         $out['title'] = _L('Login using Facebook');
  40.                         $out['icon']  = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png';
  41.  
  42.                         if (!OIDplus::baseConfig()->getValue('FACEBOOK_OAUTH2_ENABLED', false)) {
  43.                                 $out['icon'] = 'img/error.png';
  44.                                 $out['text'] = _L('Facebook OAuth authentication is disabled on this system.');
  45.                                 return;
  46.                         }
  47.  
  48.                         $target =
  49.                                 "https://www.facebook.com/v8.0/dialog/oauth?".
  50.                                 "client_id=".urlencode(OIDplus::baseConfig()->getValue('FACEBOOK_OAUTH2_CLIENT_ID'))."&".
  51.                                 "redirect_uri=".urlencode(OIDplus::webpath(__DIR__,OIDplus::PATH_ABSOLUTE_CANONICAL).'oauth.php')."&".
  52.                                 "state=".urlencode($_COOKIE['csrf_token_weak'])."&".
  53.                                 "scope=email";
  54.                         $out['text'] = '<p>'._L('Please wait...').'</p><script>window.location.href = '.js_escape($target).';</script>';
  55.                 }
  56.         }
  57.  
  58.         public function publicSitemap(&$out) {
  59.                 $out[] = 'oidplus:login_facebook';
  60.         }
  61.  
  62.         public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
  63.                 return true;
  64.         }
  65.  
  66.         public function tree_search($request) {
  67.                 return false;
  68.         }
  69.  
  70.         public function implementsFeature($id) {
  71.                 if (strtolower($id) == '1.3.6.1.4.1.37476.2.5.2.3.5') return true; // alternativeLoginMethods()
  72.                 if (strtolower($id) == '1.3.6.1.4.1.37476.2.5.2.3.8') return true; // getNotifications()
  73.                 return false;
  74.         }
  75.  
  76.         public function alternativeLoginMethods() {
  77.                 // Interface 1.3.6.1.4.1.37476.2.5.2.3.5
  78.                 $logins = array();
  79.                 if (OIDplus::baseConfig()->getValue('FACEBOOK_OAUTH2_ENABLED', false)) {
  80.                         $logins[] = array(
  81.                                 'oidplus:login_facebook',
  82.                                 _L('Login using Facebook'),
  83.                                 OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png'
  84.                         );
  85.                 }
  86.                 return $logins;
  87.         }
  88.  
  89.         public function getNotifications($user=null): array {
  90.                 // Interface 1.3.6.1.4.1.37476.2.5.2.3.8
  91.                 $notifications = array();
  92.                 if ((!$user || ($user == 'admin')) && OIDplus::authUtils()->isAdminLoggedIn()) {
  93.                         if (OIDplus::baseConfig()->getValue('FACEBOOK_OAUTH2_ENABLED', false)) {
  94.                                 if (!function_exists('curl_init')) {
  95.                                         $title = _L('Facebook OAuth Login');
  96.                                         $notifications[] = array('ERR', _L('OIDplus plugin "%1" is enabled, but the required PHP extension "%2" is not installed.', htmlentities($title), 'php_curl'));
  97.                                 }
  98.                         }
  99.                 }
  100.                 return $notifications;
  101.         }
  102.  
  103. }
  104.