64,6 → 64,13 |
list($header,$payload,$signature) = explode('.', $id_token); |
$email = json_decode(base64_decode($payload),true)['email']; |
|
// Everything's done! Now login and/or create account |
|
if (!empty($email)) { |
$ra = new OIDplusRA($email); |
if (!$ra->existing()) { |
$ra->register_ra(null); // create a user account without password |
|
// Query user infos |
$ch = curl_init('https://www.googleapis.com/oauth2/v3/userinfo'); // Initialise cURL |
$data_string = ''; |
80,6 → 87,21 |
$data = json_decode($result,true); |
$personal_name = $data['name']; // = given_name + " " + family_name |
|
OIDplus::db()->query("update ###ra set ra_name = ?, personal_name = ? where email = ?", array($personal_name, $personal_name, $email)); |
|
OIDplus::logger()->log("[INFO]RA($email)!", "RA '$email' was created because of successful Google OAuth2 login"); |
} |
|
OIDplus::logger()->log("[OK]RA($email)!", "RA '$email' logged in via Google OAuth2"); |
OIDplus::authUtils()::raLogin($email); |
|
OIDplus::db()->query("UPDATE ###ra set last_login = ".OIDplus::db()->sqlDate()." where email = ?", array($email)); |
|
// Go back to OIDplus |
|
header('Location:'.OIDplus::getSystemUrl(false)); |
} |
|
// We now have the data of the person that wanted to log in |
// So we can log off again |
$ch = curl_init(); |
94,25 → 116,3 |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
curl_exec($ch); |
curl_close($ch); |
|
// Everything's done! Now login and/or create account |
|
if (!empty($email)) { |
$ra = new OIDplusRA($email); |
if (!$ra->existing()) { |
$ra->register_ra(null); // create a user account without password |
|
OIDplus::db()->query("update ###ra set ra_name = ?, personal_name = ? where email = ?", array($personal_name, $personal_name, $email)); |
|
OIDplus::logger()->log("[INFO]RA($email)!", "RA '$email' was created because of successful Google OAuth2 login"); |
} |
|
OIDplus::logger()->log("[OK]RA($email)!", "RA '$email' logged in via Google OAuth2"); |
OIDplus::authUtils()::raLogin($email); |
|
OIDplus::db()->query("UPDATE ###ra set last_login = ".OIDplus::db()->sqlDate()." where email = ?", array($email)); |
|
// Go back to OIDplus |
|
header('Location:'.OIDplus::getSystemUrl(false)); |
} |