Subversion Repositories oidplus

Rev

Rev 635 | Rev 801 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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