Subversion Repositories oidplus

Rev

Rev 436 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
436 daniel-mar 1
<?php
2
 
3
/*
4
 * OIDplus 2.0
5
 * Copyright 2020 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
class OIDplusPagePublicLoginFacebook extends OIDplusPagePluginPublic {
21
 
22
        public function action($actionID, $params) {
23
                throw new OIDplusException(_L('Unknown action ID'));
24
        }
25
 
26
        public function init($html=true) {
27
                // Nothing
28
        }
29
 
30
        public function gui($id, &$out, &$handled) {
31
                if ($id === 'oidplus:login_facebook') {
32
                        $handled = true;
33
                        $out['title'] = _L('Login using Facebook');
34
                        $out['icon']  = OIDplus::webpath(__DIR__).'icon_big.png';
35
 
36
                        if (!OIDplus::baseConfig()->getValue('FACEBOOK_OAUTH2_ENABLED', false)) {
37
                                $out['icon'] = 'img/error_big.png';
38
                                $out['text'] = _L('Facebook OAuth authentication is disabled on this system.');
39
                                return;
40
                        }
41
 
42
                        $target =
43
                                "https://www.facebook.com/v8.0/dialog/oauth?".
44
                                "client_id=".urlencode(OIDplus::baseConfig()->getValue('FACEBOOK_OAUTH2_CLIENT_ID'))."&".
496 daniel-mar 45
                                "redirect_uri=".urlencode(OIDplus::webpath(__DIR__,false).'oauth.php')."&".
436 daniel-mar 46
                                "state=".urlencode($_COOKIE['csrf_token'])."&".
47
                                "scope=email";
48
                        $out['text'] = '<p>'._L('Please wait...').'</p><script>window.location.href = '.js_escape($target).';</script>';
49
                }
50
        }
51
 
52
        public function publicSitemap(&$out) {
53
                $out[] = 'oidplus:login_facebook';
54
        }
55
 
56
        public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
57
                return true;
58
        }
59
 
60
        public function tree_search($request) {
61
                return false;
62
        }
63
 
64
        public function implementsFeature($id) {
65
                if (strtolower($id) == '1.3.6.1.4.1.37476.2.5.2.3.5') return true; // alternativeLoginMethods
66
                return false;
67
        }
68
 
69
        public function alternativeLoginMethods() {
70
                $logins = array();
71
                if (OIDplus::baseConfig()->getValue('FACEBOOK_OAUTH2_ENABLED', false)) {
72
                        $logins[] = array(
73
                                'oidplus:login_facebook',
74
                                _L('Login using Facebook'),
75
                                OIDplus::webpath(__DIR__).'treeicon.png'
76
                        );
77
                }
78
                return $logins;
79
        }
80
}