Skip to content

Commit

Permalink
Support for YubiKey OTP 2 factor authenticator
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Jan 11, 2022
1 parent c763004 commit 0f05d06
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,7 @@
## mm/dd/2022

1. [](#new)
* Support for `YubiKey OTP` 2-Factor authenticator
* New `elements` container field that shows/hides children fields based on boolean trigger value
2. [](#improved)
* Added new asset language strings
Expand Down
7 changes: 6 additions & 1 deletion classes/plugin/Controllers/Login/LoginController.php
Expand Up @@ -278,8 +278,13 @@ public function taskTwofa(): ResponseInterface
$code = $data['2fa_code'] ?? null;
$secret = $user->twofa_secret ?? null;
$redirect = (string)$this->getRequest()->getUri();
$twofa_valid = $twoFa->verifyCode($secret, $code);

if (null === $twoFa || !$user->authenticated || !$code || !$secret || !$twoFa->verifyCode($secret, $code)) {
$yubikey_otp = $data['yubikey_otp'] ?? null;
$yubikey_id = $user->yubikey_id ?? null;
$yubikey_valid = $twoFa->verifyYubikeyOTP($yubikey_id, $yubikey_otp);

if (null === $twoFa || !$user->authenticated || (!$twofa_valid && !$yubikey_valid) ) {
Admin::DEBUG && Admin::addDebugMessage('Admin login: 2FA check failed, log out!');

// Failed 2FA auth, logout and redirect to the current page.
Expand Down
3 changes: 3 additions & 0 deletions languages/en.yaml
Expand Up @@ -758,6 +758,9 @@ PLUGIN_ADMIN:
2FA_SECRET: "2FA Secret"
2FA_SECRET_HELP: "Scan this QR code into your [Authenticator App](https://learn.getgrav.org/admin-panel/2fa#apps). Also it's a good idea to backup the secret in a safe location, in case you need to reinstall your app. Check the [Grav docs](https://learn.getgrav.org/admin-panel/2fa) for more information "
2FA_REGENERATE: "Regenerate"
YUBIKEY_ID: "YubiKey ID"
YUBIKEY_OTP_INPUT: "YubiKey OTP"
YUBIKEY_HELP: "Insert your YubiKey into your computer and click the button to generate an OTP. The first 12 chars are your client ID and will be saved."
FORCE_LOWERCASE_URLS: "Force lowercase URLs"
FORCE_LOWERCASE_URLS_HELP: "By default Grav will set all slugs and routes to be lowercase. With this set to false, Uppercase slugs and routes can be used"
INTL_ENABLED: "Intl module integration"
Expand Down
5 changes: 5 additions & 0 deletions pages/admin/login.md
Expand Up @@ -37,4 +37,9 @@ forms:
id: twofa-code
autofocus: true
placeholder: PLUGIN_ADMIN.2FA_CODE_INPUT
description: or
yubikey_otp:
type: text
id: yubikey-otp
placeholder: PLUGIN_ADMIN.YUBIKEY_OTP_INPUT
---
6 changes: 6 additions & 0 deletions themes/grav/css-compiled/template.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion themes/grav/css-compiled/template.css.map

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions themes/grav/scss/template/_login.scss
Expand Up @@ -57,6 +57,7 @@
width: 100%;
@include flex(1);
}

}

.form-field {
Expand All @@ -72,6 +73,14 @@
padding-right: 0;
}

.form-description {
display: block;
margin-top: -15px;
padding-bottom: 15px;
text-align: center;
font-size: 110%;
}

.wrapper-spacer {
width: 100% !important;
display: block !important;
Expand Down

0 comments on commit 0f05d06

Please sign in to comment.