Skip to content

Commit 4f23686

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

File tree

4 files changed

+56
-7
lines changed

4 files changed

+56
-7
lines changed

web/profiles/custom/os2loop/modules/os2loop_cura_login/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ configuration.
99
curl "http://$(docker compose port nginx 8080)/os2loop-cura-login/start"
1010
```
1111

12-
1312
``` shell
1413
drush os2loop-cura-login:get-login-url --help
1514
```
@@ -18,7 +17,6 @@ drush os2loop-cura-login:get-login-url --help
1817
drush --uri='http://nginx:8080' os2loop-cura-login:get-login-url [email protected] --secret=$(drush config:get --format string os2loop_cura_login.settings signing_secret --include-overridden) --algorithm=$(drush config:get --format string os2loop_cura_login.settings signing_algorithm --include-overridden)
1918
```
2019

21-
2220
## Development and debugging
2321

2422
``` php

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: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,33 +59,67 @@ public function __construct(
5959
*/
6060
public function start(Request $request): Response {
6161
try {
62-
$this->info('Request: @request', [
63-
'@request' => json_encode([
62+
$content = NULL;
63+
try {
64+
$content = (string) $request->getContent();
65+
} catch (\Exception) {}
66+
$this->debug('@debug', [
67+
'@debug' => json_encode([
6468
'method' => $request->getMethod(),
6569
'query' => $request->query->all(),
66-
'content' => (string) $request->getContent(),
70+
'content' => $content,
6771
]),
6872
]);
6973

7074
$jwt = Request::METHOD_POST === $request->getMethod()
7175
? $request->getContent()
7276
: $request->query->getString($this->config->get('token_param_name') ?? 'token');
7377

78+
$this->debug('@debug', [
79+
'@debug' => json_encode([
80+
'jwt' => $jwt,
81+
]),
82+
]);
83+
84+
if (empty($jwt)) {
85+
throw new BadRequestHttpException('Missing or empty JWT');
86+
}
87+
7488
$payload = (array) JWT::decode($jwt, new Key($this->config->get('signing_secret'), $this->config->get('signing_algorithm')));
7589

90+
$this->debug('@debug', [
91+
'@debug' => json_encode([
92+
'payload' => $payload,
93+
]),
94+
]);
95+
7696
$username = $payload['username'] ?? NULL;
7797
if (empty($username)) {
7898
throw new BadRequestHttpException('Missing username');
7999
}
80100

81101
$user = $this->loadUser($username);
102+
103+
$this->debug('@debug', [
104+
'@debug' => json_encode([
105+
'user' => $user,
106+
]),
107+
]);
108+
82109
if (empty($user)) {
83110
// Don't disclose whether or not the user exists.
84111
throw new BadRequestHttpException();
85112
}
86113

87114
// Check that we can get userinfo.
88115
$userinfo = $this->getUserinfo($user);
116+
117+
$this->debug('@debug', [
118+
'@debug' => json_encode([
119+
'userinfo' => $userinfo,
120+
]),
121+
]);
122+
89123
if (empty($userinfo)) {
90124
throw new BadRequestHttpException();
91125
}

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)