-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple_oauth.module
62 lines (56 loc) · 1.64 KB
/
simple_oauth.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/**
* @file
* Contains simple_oauth.module..
*/
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function simple_oauth_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the simple_oauth module.
case 'help.page.simple_oauth':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The OAuth 2.0 Authorization Framework: Bearer Token Usage') . '</p>';
return $output;
default:
}
}
/**
* Implements hook_cron().
*/
function simple_oauth_cron() {
/* @var \Drupal\Core\Entity\EntityManagerInterface $manager */
$manager = \Drupal::service('entity.manager');
$storage = $manager->getStorage('access_token');
$query = $storage->getQuery();
// We only delete access tokens when deleting their expired refresh tokens.
$ids = $query
->condition('expire', REQUEST_TIME, '<')
->condition('resource', 'authentication')
->execute();
if (!empty($ids)) {
$refresh_tokens = $storage->loadMultiple($ids);
// Get the access tokens associated to this refresh token.
$access_tokens = array_map(function ($refresh_token) {
return $refresh_token->get('access_token_id')->entity;
}, $refresh_tokens);
// Delete the access tokens.
$storage->delete(array_filter($access_tokens));
// Delete the refresh tokens.
$storage->delete($refresh_tokens);
}
}
/**
* Implements hook_theme().
*/
function simple_oauth_theme($existing, $type, $theme, $path) {
return [
'access_token' => [
'render element' => 'access_token',
'file' => 'access_token.page.inc',
],
];
}