diff --git a/src/transformer/utils/get_user.php b/src/transformer/utils/get_user.php index 385640124..5c8b55afd 100644 --- a/src/transformer/utils/get_user.php +++ b/src/transformer/utils/get_user.php @@ -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;