Skip to content

Commit

Permalink
Update get_user.php
Browse files Browse the repository at this point in the history
fix an issue where a user may have multiple ouath2 providers
  • Loading branch information
sei-ebram authored Jan 7, 2021
1 parent 095ebe3 commit 3ecccee
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions src/transformer/utils/get_user.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,35 @@ function get_user(array $config, \stdClass $user) {
function get_homePage(array $config, \stdClass $user) {
$repo = $config['repo'];
$homePage = $config['app_url'];

// check if the value is set to use OAuth2 issuer as homePage
// check if the value is set to use OAuth2 issuer as homePag
if (array_key_exists('send_oauth2_issuer', $config) && $config['send_oauth2_issuer'] == true) {
// check if this user is logged in via OAuth2
if (isset($user->auth) && $user->auth == 'oauth2') {
try {
// find the oauth2 issuer that this user is logged in under
$issuerid = $repo->read_record('auth_oauth2_linked_login', [
$issuerids = $repo->read_records('auth_oauth2_linked_login', [
'userid' => $user->id
])->issuerid;
// get the issuer's baseurl
$issueridbaseurl = $repo->read_record_by_id('oauth2_issuer', $issuerid)->baseurl;
if (isset($issueridbaseurl)) {
// if the baseurl is properly found, set the homePage to it
$homePage = $issueridbaseurl;
]);
// check to see if there are any issuerids associated with this user
if (isset($issuerids) && count($issuerids) > 0) {
// sort by timemodified to get the newest first,
// it'd be nice if there was a field to see the active oauth2 issuer the user is
// logged in with, but that doesn't seem to be stored
usort($issuerids, function($a, $b) {
return $b->timemodified - $a->timemodified;
});
// pull the top issuerid value
$issuerid = $issuerids[0]->issuerid;
// get the issuer's baseurl
$issueridbaseurl = $repo->read_record_by_id('oauth2_issuer', $issuerid)->baseurl;
if (isset($issueridbaseurl)) {
// if the baseurl is properly found, set the homePage to it
$homePage = $issueridbaseurl;
}
}
} catch (\Exception $e) { }
} catch (\Exception $e) {
debugging($e->getMessage());
}
}
}
return $homePage;
Expand Down

0 comments on commit 3ecccee

Please sign in to comment.