Subversion Repositories oidplus

Rev

Rev 1116 | Rev 1131 | 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
1086 daniel-mar 5
 * Copyright 2019 - 2023 Daniel Marschall, ViaThinkSoft
635 daniel-mar 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
 
1086 daniel-mar 22
// phpcs:disable PSR1.Files.SideEffects
23
\defined('INSIDE_OIDPLUS') or die;
24
// phpcs:enable PSR1.Files.SideEffects
25
 
635 daniel-mar 26
class OIDplusPagePublicLoginFacebook extends OIDplusPagePluginPublic {
27
 
1116 daniel-mar 28
        /**
29
         * @param string $actionID
30
         * @param array $params
31
         * @return array
32
         * @throws OIDplusException
33
         */
34
        public function action(string $actionID, array $params): array {
35
                return parent::action($actionID, $params);
635 daniel-mar 36
        }
37
 
1116 daniel-mar 38
        /**
39
         * @param bool $html
40
         * @return void
41
         */
42
        public function init(bool $html=true) {
635 daniel-mar 43
                // Nothing
44
        }
45
 
1116 daniel-mar 46
        /**
47
         * @param string $id
48
         * @param array $out
49
         * @param bool $handled
50
         * @return void
51
         * @throws OIDplusException
52
         */
53
        public function gui(string $id, array &$out, bool &$handled) {
635 daniel-mar 54
                if ($id === 'oidplus:login_facebook') {
55
                        $handled = true;
56
                        $out['title'] = _L('Login using Facebook');
801 daniel-mar 57
                        $out['icon']  = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png';
635 daniel-mar 58
 
59
                        if (!OIDplus::baseConfig()->getValue('FACEBOOK_OAUTH2_ENABLED', false)) {
800 daniel-mar 60
                                $out['icon'] = 'img/error.png';
635 daniel-mar 61
                                $out['text'] = _L('Facebook OAuth authentication is disabled on this system.');
62
                                return;
63
                        }
64
 
65
                        $target =
66
                                "https://www.facebook.com/v8.0/dialog/oauth?".
67
                                "client_id=".urlencode(OIDplus::baseConfig()->getValue('FACEBOOK_OAUTH2_CLIENT_ID'))."&".
801 daniel-mar 68
                                "redirect_uri=".urlencode(OIDplus::webpath(__DIR__,OIDplus::PATH_ABSOLUTE_CANONICAL).'oauth.php')."&".
635 daniel-mar 69
                                "state=".urlencode($_COOKIE['csrf_token_weak'])."&".
70
                                "scope=email";
71
                        $out['text'] = '<p>'._L('Please wait...').'</p><script>window.location.href = '.js_escape($target).';</script>';
72
                }
73
        }
74
 
1116 daniel-mar 75
        /**
76
         * @param array $out
77
         * @return void
78
         */
79
        public function publicSitemap(array &$out) {
635 daniel-mar 80
                $out[] = 'oidplus:login_facebook';
81
        }
82
 
1116 daniel-mar 83
        /**
84
         * @param array $json
85
         * @param string|null $ra_email
86
         * @param bool $nonjs
87
         * @param string $req_goto
88
         * @return bool
89
         */
90
        public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool {
635 daniel-mar 91
                return true;
92
        }
93
 
1116 daniel-mar 94
        /**
95
         * @param string $request
96
         * @return array|false
97
         */
98
        public function tree_search(string $request) {
635 daniel-mar 99
                return false;
100
        }
101
 
1116 daniel-mar 102
        /**
103
         * @param string $id
104
         * @return bool
105
         */
106
        public function implementsFeature(string $id): bool {
1000 daniel-mar 107
                if (strtolower($id) == '1.3.6.1.4.1.37476.2.5.2.3.5') return true; // alternativeLoginMethods()
108
                if (strtolower($id) == '1.3.6.1.4.1.37476.2.5.2.3.8') return true; // getNotifications()
635 daniel-mar 109
                return false;
110
        }
111
 
1116 daniel-mar 112
        /**
113
         * Implements interface 1.3.6.1.4.1.37476.2.5.2.3.5
114
         * @return array
115
         * @throws OIDplusException
116
         */
1130 daniel-mar 117
        public function alternativeLoginMethods(): array {
635 daniel-mar 118
                $logins = array();
119
                if (OIDplus::baseConfig()->getValue('FACEBOOK_OAUTH2_ENABLED', false)) {
120
                        $logins[] = array(
121
                                'oidplus:login_facebook',
122
                                _L('Login using Facebook'),
801 daniel-mar 123
                                OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png'
635 daniel-mar 124
                        );
125
                }
126
                return $logins;
127
        }
1000 daniel-mar 128
 
1116 daniel-mar 129
        /**
130
         * Implements interface 1.3.6.1.4.1.37476.2.5.2.3.8
1130 daniel-mar 131
         * @param string|null $user
1116 daniel-mar 132
         * @return array
133
         * @throws OIDplusException
134
         */
1130 daniel-mar 135
        public function getNotifications(string $user=null): array {
1000 daniel-mar 136
                $notifications = array();
137
                if ((!$user || ($user == 'admin')) && OIDplus::authUtils()->isAdminLoggedIn()) {
138
                        if (OIDplus::baseConfig()->getValue('FACEBOOK_OAUTH2_ENABLED', false)) {
139
                                if (!function_exists('curl_init')) {
140
                                        $title = _L('Facebook OAuth Login');
1008 daniel-mar 141
                                        $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 142
                                }
143
                        }
144
                }
145
                return $notifications;
146
        }
147
 
635 daniel-mar 148
}