Skip to content

Commit 5fa22d1

Browse files
authored
fix: remove otp settings for service account app types (#77)
* fix: remove otp settings for service account app types Signed-off-by: romanetar <[email protected]> * fix: remove otp settings for service account app types Signed-off-by: romanetar <[email protected]> * fix: remove otp settings for service account app types Signed-off-by: romanetar <[email protected]> --------- Signed-off-by: romanetar <[email protected]>
1 parent b368424 commit 5fa22d1

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

app/Models/OAuth2/Client.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@
4343
#[ORM\Cache('NONSTRICT_READ_WRITE')] // Class Client
4444
class Client extends BaseEntity implements IClient
4545
{
46+
private static array $allowed_otp_client_types = [
47+
IClient::ApplicationType_JS_Client,
48+
IClient::ApplicationType_Native,
49+
IClient::ApplicationType_Web_App
50+
];
51+
4652
/**
4753
* @var string
4854
*/
@@ -1667,6 +1673,10 @@ public function isPasswordlessEnabled(): bool
16671673

16681674
public function enablePasswordless(): void
16691675
{
1676+
$app_type = $this->getApplicationType();
1677+
if (!in_array($this->getApplicationType(), self::$allowed_otp_client_types)) {
1678+
throw new ValidationException("This application type ($app_type) does not allow passwordless.");
1679+
}
16701680
$this->otp_enabled = true;
16711681
$this->otp_length = intval(Config::get("otp.length"));
16721682
$this->otp_lifetime = intval(Config::get("otp.lifetime"));

resources/js/oauth2/profile/edit_client/actions.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,12 @@ const normalizeEntity = (entity, entitySection) => {
153153
normEntity.pkce_enabled = entity.pkce_enabled ? 1 : 0;
154154
normEntity = normalizePKCEDependencies(normEntity);
155155
}
156-
normEntity.otp_enabled = entity.otp_enabled ? 1 : 0;
157-
normEntity.otp_length = entity.otp_length;
158-
normEntity.otp_lifetime = entity.otp_lifetime;
156+
normEntity.otp_enabled = 0;
157+
if (entity.otp_enabled) {
158+
normEntity.otp_enabled = 1;
159+
normEntity.otp_length = entity.otp_length;
160+
normEntity.otp_lifetime = entity.otp_lifetime;
161+
}
159162

160163
if ([appTypes.JSClient, appTypes.Native, appTypes.WebApp].includes(entity.application_type))
161164
normEntity.max_allowed_user_sessions = entity.max_allowed_user_sessions;

resources/js/oauth2/profile/edit_client/components/security_settings_panel.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,16 @@ const SecuritySettingsPanel = (
7171
onChange={handleUsePKCEChange}
7272
/>
7373
}
74-
<CheckboxFormControl
75-
id="otp_enabled"
76-
title="Use Passwordless?"
77-
tooltip="Use Passwordless Authentication"
78-
value={formik.values.otp_enabled}
79-
onChange={formik.handleChange}
80-
/>
74+
{
75+
[appTypes.JSClient, appTypes.Native, appTypes.WebApp].includes(application_type) &&
76+
<CheckboxFormControl
77+
id="otp_enabled"
78+
title="Use Passwordless?"
79+
tooltip="Use Passwordless Authentication"
80+
value={formik.values.otp_enabled}
81+
onChange={formik.handleChange}
82+
/>
83+
}
8184
{
8285
formik.values.otp_enabled &&
8386
<>

0 commit comments

Comments
 (0)