Skip to content

Commit 4f2f451

Browse files
committed
5124: Improved stuff
1 parent 37c677d commit 4f2f451

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

web/profiles/custom/os2loop/modules/os2loop_cura_login/os2loop_cura_login.routing.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
os2loop_cura_login.start:
22
path: '/os2loop-cura-login/start'
33
defaults:
4-
_title: 'Start login hack'
4+
_title: 'Start Cura login'
55
_controller: '\Drupal\os2loop_cura_login\Controller\Os2loopCuraLoginController::start'
66
methods: [GET, POST]
77
requirements:
@@ -10,7 +10,7 @@ os2loop_cura_login.start:
1010
os2loop_cura_login.authenticate:
1111
path: '/os2loop-login-hack/authenticate'
1212
defaults:
13-
_title: 'Authenticate'
13+
_title: 'Authenticate with Cura login'
1414
_controller: '\Drupal\os2loop_cura_login\Controller\Os2loopCuraLoginController::authenticate'
1515
methods: [GET]
1616
requirements:

web/profiles/custom/os2loop/modules/os2loop_cura_login/src/Controller/Os2loopCuraLoginController.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function __construct(
5959
*/
6060
public function start(Request $request): Response {
6161
try {
62-
$this->info('Request: @request', [
62+
$this->debug('Request: @request', [
6363
'@request' => json_encode([
6464
'method' => $request->getMethod(),
6565
'query' => $request->query->all(),
@@ -70,6 +70,9 @@ public function start(Request $request): Response {
7070
$jwt = Request::METHOD_POST === $request->getMethod()
7171
? $request->getContent()
7272
: $request->query->getString($this->config->get('token_param_name') ?? 'token');
73+
if (empty($jwt)) {
74+
throw new BadRequestHttpException('Missing or empty JWT');
75+
}
7376

7477
$payload = (array) JWT::decode($jwt, new Key($this->config->get('signing_secret'), $this->config->get('signing_algorithm')));
7578

web/profiles/custom/os2loop/modules/os2loop_cura_login/src/Form/SettingsForm.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Drupal\Core\Form\ConfigFormBase;
99
use Drupal\Core\Form\FormStateInterface;
1010
use Drupal\Core\Logger\RfcLogLevel;
11+
use Drupal\Core\Url;
1112

1213
/**
1314
* Configure OS2Loop Cura login settings for this site.
@@ -79,6 +80,22 @@ public function buildForm(array $form, FormStateInterface $form_state): array {
7980
'#default_value' => $config->get('log_level') ?? RfcLogLevel::ERROR,
8081
];
8182

83+
$authenticationStartUrl = Url::fromRoute('os2loop_cura_login.start')->setAbsolute()->toString(true)->getGeneratedUrl();
84+
$form['info'] = [
85+
'#theme' => 'item_list',
86+
'#items' => [
87+
'#markup' => $this->t('Use <a href=":url">:url</a> as <code>linkURL</code>.', [':url' => $authenticationStartUrl]),
88+
],
89+
];
90+
91+
if ($name = $config->get('token_param_name')) {
92+
$authenticationStartUrl = Url::fromRoute('os2loop_cura_login.start', [$name => ''])->setAbsolute()->toString(true)->getGeneratedUrl();
93+
$authenticationStartUrl = str_replace(urlencode(''), '', $authenticationStartUrl);
94+
$form['info']['#items'][] = [
95+
'#markup' => $this->t('Use <a href=":url">:url</a> as <code>linkURL</code> for <core>GET</core>.', [':url' => $authenticationStartUrl]),
96+
];
97+
}
98+
8299
return parent::buildForm($form, $form_state);
83100
}
84101

0 commit comments

Comments
 (0)