This repository has been archived by the owner on Jan 4, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple_oauth_auth_code.module
95 lines (86 loc) · 2.7 KB
/
simple_oauth_auth_code.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
/**
* @file
* Contains simple_oauth_auth_code.module.
*/
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
/**
* Implements hook_entity_base_field_info().
*/
function simple_oauth_auth_code_entity_base_field_info(EntityTypeInterface $entity_type) {
$fields = [];
if ($entity_type->id() == 'consumer') {
$fields['one_time_login_auth_code_expiration'] = BaseFieldDefinition::create('integer')
->setLabel(new TranslatableMarkup('OTL auth code expiration'))
->setDescription(new TranslatableMarkup('Expiration time in seconds of the authorization code when used for one time logins via the simple_oauth_auth_code module.'))
->setDisplayOptions('view', [
'label' => 'inline',
'weight' => 6,
])
->setDisplayOptions('form', [
'weight' => 6,
])
->setRevisionable(TRUE)
->setTranslatable(FALSE)
->setRequired(TRUE)
->setSetting('unsigned', TRUE)
->setDefaultValue(900);
}
return $fields;
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function simple_oauth_auth_code_form_consumer_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
$stateVisibleIfAuthorizationCodeGrantEnabled = [
'#states' => [
'visible' => [
':input[name="grant_types[authorization_code]"]' => [
'checked' => TRUE,
],
],
],
];
$form['one_time_login_auth_code_settings_info'] = [
'#type' => 'details',
'#title' => new TranslatableMarkup('One Time Login Auth Code Settings'),
'#open' => TRUE,
'#weight' => 3,
'info' => [
'#type' => 'html_tag',
'#tag' => 'div',
'#value' => new TranslatableMarkup('The <strong>Authorization Code</strong> grant MUST be enabled for one time login auth codes to work!'),
'#attributes' => [
'class' => ['messages', 'messages--warning'],
],
],
'#states' => [
'visible' => [
':input[name="grant_types[authorization_code]"]' => [
'checked' => FALSE,
],
],
],
];
$form['one_time_login_auth_code_settings'] = [
'#type' => 'details',
'#title' => new TranslatableMarkup('One Time Login Auth Code Settings'),
'#open' => TRUE,
'#weight' => 3,
'#states' => [
'visible' => [
':input[name="grant_types[authorization_code]"]' => [
'checked' => TRUE,
],
],
],
'one_time_login_auth_code_expiration' => array_merge(
$form['one_time_login_auth_code_expiration'],
$stateVisibleIfAuthorizationCodeGrantEnabled,
),
];
unset($form['one_time_login_auth_code_expiration']);
}