Rev 1008 | Rev 1086 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
635 | daniel-mar | 1 | <?php |
2 | |||
3 | /* |
||
4 | * OIDplus 2.0 |
||
5 | * Copyright 2019 - 2021 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 | |||
1050 | daniel-mar | 20 | namespace ViaThinkSoft\OIDplus; |
635 | daniel-mar | 21 | |
22 | class OIDplusPagePublicLoginFacebook extends OIDplusPagePluginPublic { |
||
23 | |||
24 | public function action($actionID, $params) { |
||
25 | throw new OIDplusException(_L('Unknown action ID')); |
||
26 | } |
||
27 | |||
28 | public function init($html=true) { |
||
29 | // Nothing |
||
30 | } |
||
31 | |||
32 | public function gui($id, &$out, &$handled) { |
||
33 | if ($id === 'oidplus:login_facebook') { |
||
34 | $handled = true; |
||
35 | $out['title'] = _L('Login using Facebook'); |
||
801 | daniel-mar | 36 | $out['icon'] = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png'; |
635 | daniel-mar | 37 | |
38 | if (!OIDplus::baseConfig()->getValue('FACEBOOK_OAUTH2_ENABLED', false)) { |
||
800 | daniel-mar | 39 | $out['icon'] = 'img/error.png'; |
635 | daniel-mar | 40 | $out['text'] = _L('Facebook OAuth authentication is disabled on this system.'); |
41 | return; |
||
42 | } |
||
43 | |||
44 | $target = |
||
45 | "https://www.facebook.com/v8.0/dialog/oauth?". |
||
46 | "client_id=".urlencode(OIDplus::baseConfig()->getValue('FACEBOOK_OAUTH2_CLIENT_ID'))."&". |
||
801 | daniel-mar | 47 | "redirect_uri=".urlencode(OIDplus::webpath(__DIR__,OIDplus::PATH_ABSOLUTE_CANONICAL).'oauth.php')."&". |
635 | daniel-mar | 48 | "state=".urlencode($_COOKIE['csrf_token_weak'])."&". |
49 | "scope=email"; |
||
50 | $out['text'] = '<p>'._L('Please wait...').'</p><script>window.location.href = '.js_escape($target).';</script>'; |
||
51 | } |
||
52 | } |
||
53 | |||
54 | public function publicSitemap(&$out) { |
||
55 | $out[] = 'oidplus:login_facebook'; |
||
56 | } |
||
57 | |||
58 | public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') { |
||
59 | return true; |
||
60 | } |
||
61 | |||
62 | public function tree_search($request) { |
||
63 | return false; |
||
64 | } |
||
65 | |||
66 | public function implementsFeature($id) { |
||
1000 | daniel-mar | 67 | if (strtolower($id) == '1.3.6.1.4.1.37476.2.5.2.3.5') return true; // alternativeLoginMethods() |
68 | if (strtolower($id) == '1.3.6.1.4.1.37476.2.5.2.3.8') return true; // getNotifications() |
||
635 | daniel-mar | 69 | return false; |
70 | } |
||
71 | |||
72 | public function alternativeLoginMethods() { |
||
1000 | daniel-mar | 73 | // Interface 1.3.6.1.4.1.37476.2.5.2.3.5 |
635 | daniel-mar | 74 | $logins = array(); |
75 | if (OIDplus::baseConfig()->getValue('FACEBOOK_OAUTH2_ENABLED', false)) { |
||
76 | $logins[] = array( |
||
77 | 'oidplus:login_facebook', |
||
78 | _L('Login using Facebook'), |
||
801 | daniel-mar | 79 | OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png' |
635 | daniel-mar | 80 | ); |
81 | } |
||
82 | return $logins; |
||
83 | } |
||
1000 | daniel-mar | 84 | |
85 | public function getNotifications($user=null): array { |
||
86 | // Interface 1.3.6.1.4.1.37476.2.5.2.3.8 |
||
87 | $notifications = array(); |
||
88 | if ((!$user || ($user == 'admin')) && OIDplus::authUtils()->isAdminLoggedIn()) { |
||
89 | if (OIDplus::baseConfig()->getValue('FACEBOOK_OAUTH2_ENABLED', false)) { |
||
90 | if (!function_exists('curl_init')) { |
||
91 | $title = _L('Facebook OAuth Login'); |
||
1008 | daniel-mar | 92 | $notifications[] = array('ERR', _L('OIDplus plugin "%1" is enabled, but the required PHP extension "%2" is not installed.', htmlentities($title), 'php_curl')); |
1000 | daniel-mar | 93 | } |
94 | } |
||
95 | } |
||
96 | return $notifications; |
||
97 | } |
||
98 | |||
635 | daniel-mar | 99 | } |