Skip to content

Commit

Permalink
Bugfix of refreshing
Browse files Browse the repository at this point in the history
  • Loading branch information
jasperweyne committed Oct 27, 2020
1 parent ac87732 commit f9f8d94
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
14 changes: 12 additions & 2 deletions main.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function random_pass($length = 16, $keyspace = "abcdefghijklmnopqrstuvwxyzABCDEF
*/
function is_token_unexpired($access_token): bool
{
return isset($access_token->expires_at) && $access_token->expires_at >= time();
return isset($access_token->expires) && $access_token->expires >= time();
}

/// Event handlers
Expand Down Expand Up @@ -195,7 +195,17 @@ function refresh_login($user)
// Try to obtain refreshed access token
try {
$oidc = get_oidc_client();
$_SESSION[OIDC_SESSION] = json_encode($oidc->refreshToken($accessToken->refresh_token));
$response = $oidc->refreshToken($accessToken->refresh_token);
if (isset($response->refresh_token)) {
$accessToken->refresh_token = $response->refresh_token;
}
if (isset($response->access_token)) {
$accessToken->access_token = $response->access_token;
}
if (isset($response->expires_in)) {
$accessToken->expires = time() + $response->expires_in;
}
$_SESSION[OIDC_SESSION] = json_encode($accessToken);
} catch (\Exception $e) {
// Log out if an unknown problem arises
$page['errors'][] = $e->getMessage();
Expand Down
6 changes: 5 additions & 1 deletion oidc.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@ function oidc_login(OpenIDConnectClient $oidc, $token, $remember_me)
$email = $oidc->requestUserInfo('email');

// Store access token in the session
$_SESSION[OIDC_SESSION] = json_encode($token);
$_SESSION[OIDC_SESSION] = json_encode([
'refresh_token' => $token['refresh_token'],
'access_token' => $token['access_token'],
'expires' => time() + $token['expires_in']
]);

// Update user data from ID token data
$fields = array($conf['user_fields']['email'], $conf['user_fields']['username']);
Expand Down

0 comments on commit f9f8d94

Please sign in to comment.