Subversion Repositories oidplus

Rev

Rev 484 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 484 Rev 496
Line 39... Line 39...
39
if (!function_exists('curl_init')) {
39
if (!function_exists('curl_init')) {
40
        die(_L('The "%1" PHP extension is not installed at your system. Please enable the PHP extension <code>%2</code>.','CURL','php_curl'));
40
        die(_L('The "%1" PHP extension is not installed at your system. Please enable the PHP extension <code>%2</code>.','CURL','php_curl'));
41
}
41
}
42
 
42
 
43
$ch = curl_init();
43
$ch = curl_init();
44
if (ini_get('curl.cainfo') == '') curl_setopt($ch, CURLOPT_CAINFO, OIDplus::basePath() . '/3p/certs/cacert.pem');
44
if (ini_get('curl.cainfo') == '') curl_setopt($ch, CURLOPT_CAINFO, OIDplus::localpath() . '3p/certs/cacert.pem');
45
curl_setopt($ch, CURLOPT_URL,"https://oauth2.googleapis.com/token");
45
curl_setopt($ch, CURLOPT_URL,"https://oauth2.googleapis.com/token");
46
curl_setopt($ch, CURLOPT_POST, 1);
46
curl_setopt($ch, CURLOPT_POST, 1);
47
curl_setopt($ch, CURLOPT_POSTFIELDS,
47
curl_setopt($ch, CURLOPT_POSTFIELDS,
48
        "grant_type=authorization_code&".
48
        "grant_type=authorization_code&".
49
        "code=".$_GET['code']."&".
49
        "code=".$_GET['code']."&".
50
        "redirect_uri=".urlencode(OIDplus::getSystemUrl(false).OIDplus::webpath(__DIR__).'oauth.php')."&".
50
        "redirect_uri=".urlencode(OIDplus::webpath(__DIR__,false).'oauth.php')."&".
51
        "client_id=".urlencode(OIDplus::baseConfig()->getValue('GOOGLE_OAUTH2_CLIENT_ID'))."&".
51
        "client_id=".urlencode(OIDplus::baseConfig()->getValue('GOOGLE_OAUTH2_CLIENT_ID'))."&".
52
        "client_secret=".urlencode(OIDplus::baseConfig()->getValue('GOOGLE_OAUTH2_CLIENT_SECRET'))
52
        "client_secret=".urlencode(OIDplus::baseConfig()->getValue('GOOGLE_OAUTH2_CLIENT_SECRET'))
53
);
53
);
54
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
54
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
55
$cont = curl_exec($ch);
55
$cont = curl_exec($ch);
Line 81... Line 81...
81
        if (!$ra->existing()) {
81
        if (!$ra->existing()) {
82
                $ra->register_ra(null); // create a user account without password
82
                $ra->register_ra(null); // create a user account without password
83
 
83
 
84
                // Query user infos
84
                // Query user infos
85
                $ch = curl_init('https://www.googleapis.com/oauth2/v3/userinfo'); // Initialise cURL
85
                $ch = curl_init('https://www.googleapis.com/oauth2/v3/userinfo'); // Initialise cURL
86
                if (ini_get('curl.cainfo') == '') curl_setopt($ch, CURLOPT_CAINFO, OIDplus::basePath() . '/3p/certs/cacert.pem');
86
                if (ini_get('curl.cainfo') == '') curl_setopt($ch, CURLOPT_CAINFO, OIDplus::localpath() . '3p/certs/cacert.pem');
87
                $data_string = '';
87
                $data_string = '';
88
                curl_setopt($ch, CURLOPT_HTTPHEADER, array(
88
                curl_setopt($ch, CURLOPT_HTTPHEADER, array(
89
                        'Content-Length: ' . strlen($data_string),
89
                        'Content-Length: ' . strlen($data_string),
90
                        "Authorization: Bearer ".$access_token
90
                        "Authorization: Bearer ".$access_token
91
                ));
91
                ));
Line 108... Line 108...
108
 
108
 
109
        OIDplus::db()->query("UPDATE ###ra set last_login = ".OIDplus::db()->sqlDate()." where email = ?", array($email));
109
        OIDplus::db()->query("UPDATE ###ra set last_login = ".OIDplus::db()->sqlDate()." where email = ?", array($email));
110
 
110
 
111
        // Go back to OIDplus
111
        // Go back to OIDplus
112
 
112
 
113
        header('Location:'.OIDplus::getSystemUrl(false));
113
        header('Location:'.OIDplus::webpath(null,false));
114
}
114
}
115
 
115
 
116
// We now have the data of the person that wanted to log in
116
// We now have the data of the person that wanted to log in
117
// So we can log off again
117
// So we can log off again
118
$ch = curl_init();
118
$ch = curl_init();
119
if (ini_get('curl.cainfo') == '') curl_setopt($ch, CURLOPT_CAINFO, OIDplus::basePath() . '/3p/certs/cacert.pem');
119
if (ini_get('curl.cainfo') == '') curl_setopt($ch, CURLOPT_CAINFO, OIDplus::localpath() . '3p/certs/cacert.pem');
120
curl_setopt($ch, CURLOPT_URL,"https://oauth2.googleapis.com/revoke");
120
curl_setopt($ch, CURLOPT_URL,"https://oauth2.googleapis.com/revoke");
121
curl_setopt($ch, CURLOPT_POST, 1);
121
curl_setopt($ch, CURLOPT_POST, 1);
122
curl_setopt($ch, CURLOPT_POSTFIELDS,
122
curl_setopt($ch, CURLOPT_POSTFIELDS,
123
        "client_id=".urlencode(OIDplus::baseConfig()->getValue('GOOGLE_OAUTH2_CLIENT_ID'))."&".
123
        "client_id=".urlencode(OIDplus::baseConfig()->getValue('GOOGLE_OAUTH2_CLIENT_ID'))."&".
124
        "client_secret=".urlencode(OIDplus::baseConfig()->getValue('GOOGLE_OAUTH2_CLIENT_SECRET'))."&".
124
        "client_secret=".urlencode(OIDplus::baseConfig()->getValue('GOOGLE_OAUTH2_CLIENT_SECRET'))."&".