Skip to content

Commit

Permalink
support auth_oidc login without installation of local_o365
Browse files Browse the repository at this point in the history
  • Loading branch information
weilai-irl committed Nov 23, 2020
1 parent f6dd909 commit 7a6b60d
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions auth/oidc/classes/loginflow/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,45 +134,47 @@ public function get_userinfo($username) {
if (!empty($o365installed) && \local_o365\feature\usersync\main::fieldmap_require_graph_api_call($eventtype)) {
$apiclient = \local_o365\utils::get_api($tokenrec->userid);
$userdata = $apiclient->get_user($tokenrec->oidcuniqid);

$updateduser = \local_o365\feature\usersync\main::apply_configured_fieldmap($userdata, new \stdClass(), 'login');
$userinfo = (array)$updateduser;
} else {
$userinfo = [];

$idtoken = \auth_oidc\jwt::instance_from_encoded($tokenrec->idtoken);

$oid = $idtoken->claim('oid');
if (!empty($oid)) {
$userdata['objectId'] = $oid;
$userinfo['objectId'] = $oid;
}

$upn = $idtoken->claim('upn');
if (!empty($upn)) {
$userdata['userPrincipalName'] = $upn;
$userinfo['userPrincipalName'] = $upn;
}

$firstname = $idtoken->claim('given_name');
if (!empty($firstname)) {
$userdata['givenName'] = $firstname;
$userinfo['givenName'] = $firstname;
}

$lastname = $idtoken->claim('family_name');
if (!empty($lastname)) {
$userdata['surname'] = $lastname;
$userinfo['surname'] = $lastname;
}

$email = $idtoken->claim('email');
if (!empty($email)) {
$userdata['mail'] = $email;
$userinfo['mail'] = $email;
} else {
if (!empty($upn)) {
$aademailvalidateresult = filter_var($upn, FILTER_VALIDATE_EMAIL);
if (!empty($aademailvalidateresult)) {
$userdata['mail'] = $aademailvalidateresult;
$userinfo['mail'] = $aademailvalidateresult;
}
}
}
}

$updateduser = \local_o365\feature\usersync\main::apply_configured_fieldmap($userdata, new \stdClass(), 'login');
$userinfo = (array)$updateduser;

return $userinfo;
}

Expand Down

0 comments on commit 7a6b60d

Please sign in to comment.