function oauth2_user_is_authenticated in OAuth2 Login 8
Same name in this branch
- 8 oauth2_user/oauth2_user.api.php \oauth2_user_is_authenticated()
- 8 oauth2_user/authenticate.inc \oauth2_user_is_authenticated()
Same name and namespace in other branches
- 7.2 oauth2_user/oauth2_user.api.php \oauth2_user_is_authenticated()
- 7.2 oauth2_user/authenticate.inc \oauth2_user_is_authenticated()
Return true if the user has a valid oauth2 access token.
2 calls to oauth2_user_is_authenticated()
- oauth2_user_get_from_server in oauth2_user/
profile.inc - Get the profile of the oauth2 user from the server.
- oauth2_user_init in oauth2_user/
authenticate.inc - Implements hook_init().
File
- oauth2_user/
oauth2_user.api.php, line 69 - Functions that can be used by other modules.
Code
function oauth2_user_is_authenticated() {
$server_url = variable_get('oauth2_login_oauth2_server', '');
$token_endpoint = $server_url . '/oauth2/token';
$client_id = variable_get('oauth2_login_client_id', '');
$auth_flow = 'server-side';
// Get the current access_token.
$id = md5($token_endpoint . $client_id . $auth_flow);
$token = oauth2_client_get_token($id);
// Check the access token.
if (empty($token['access_token'])) {
return FALSE;
}
if ($token['expiration_time'] < time() + 10) {
return FALSE;
}
return TRUE;
}