Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEATURE: Use second factor for admin confirmation
If second_factor_confirmation is true, then administrators can confirm other administrators using a second factor. This is an alternative to clicking a URL from an email.
- Loading branch information
Showing
11 changed files
with
260 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
app/assets/javascripts/discourse/app/controllers/grant-admin-second-factor.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import Controller from "@ember/controller"; | ||
import { action } from "@ember/object"; | ||
import discourseComputed from "discourse-common/utils/decorators"; | ||
import { getWebauthnCredential } from "discourse/lib/webauthn"; | ||
import ModalFunctionality from "discourse/mixins/modal-functionality"; | ||
import { SECOND_FACTOR_METHODS } from "discourse/models/user"; | ||
import I18n from "I18n"; | ||
|
||
export default Controller.extend(ModalFunctionality, { | ||
showSecondFactor: false, | ||
secondFactorMethod: SECOND_FACTOR_METHODS.TOTP, | ||
secondFactorToken: null, | ||
securityKeyCredential: null, | ||
|
||
inProgress: false, | ||
|
||
onShow() { | ||
this.setProperties({ | ||
showSecondFactor: false, | ||
secondFactorMethod: SECOND_FACTOR_METHODS.TOTP, | ||
secondFactorToken: null, | ||
securityKeyCredential: null, | ||
}); | ||
}, | ||
|
||
@discourseComputed("inProgress", "securityKeyCredential", "secondFactorToken") | ||
disabled(inProgress, securityKeyCredential, secondFactorToken) { | ||
return inProgress || (!securityKeyCredential && !secondFactorToken); | ||
}, | ||
|
||
setResult(result) { | ||
this.setProperties({ | ||
otherMethodAllowed: result.multiple_second_factor_methods, | ||
secondFactorRequired: true, | ||
showLoginButtons: false, | ||
backupEnabled: result.backup_enabled, | ||
showSecondFactor: result.totp_enabled, | ||
showSecurityKey: result.security_key_enabled, | ||
secondFactorMethod: result.security_key_enabled | ||
? SECOND_FACTOR_METHODS.SECURITY_KEY | ||
: SECOND_FACTOR_METHODS.TOTP, | ||
securityKeyChallenge: result.challenge, | ||
securityKeyAllowedCredentialIds: result.allowed_credential_ids, | ||
}); | ||
}, | ||
|
||
@action | ||
authenticateSecurityKey() { | ||
getWebauthnCredential( | ||
this.securityKeyChallenge, | ||
this.securityKeyAllowedCredentialIds, | ||
(credentialData) => { | ||
this.set("securityKeyCredential", credentialData); | ||
this.send("authenticate"); | ||
}, | ||
(errorMessage) => { | ||
this.flash(errorMessage, "error"); | ||
} | ||
); | ||
}, | ||
|
||
@action | ||
authenticate() { | ||
this.set("inProgress", true); | ||
this.model | ||
.grantAdmin({ | ||
second_factor_token: | ||
this.securityKeyCredential || this.secondFactorToken, | ||
second_factor_method: this.secondFactorMethod, | ||
timezone: moment.tz.guess(), | ||
}) | ||
.then((result) => { | ||
if (result.success) { | ||
this.send("closeModal"); | ||
bootbox.alert(I18n.t("admin.user.grant_admin_success")); | ||
} else { | ||
this.flash(result.error, "error"); | ||
this.setResult(result); | ||
} | ||
}) | ||
.finally(() => this.set("inProgress", false)); | ||
}, | ||
}); |
33 changes: 33 additions & 0 deletions
33
app/assets/javascripts/discourse/app/templates/modal/grant-admin-second-factor.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{{#d-modal-body title="admin.user.grant_admin"}} | ||
{{#second-factor-form | ||
secondFactorMethod=secondFactorMethod | ||
secondFactorToken=secondFactorToken | ||
class=secondFactorClass | ||
backupEnabled=backupEnabled | ||
}} | ||
{{#if showSecurityKey}} | ||
{{#security-key-form | ||
allowedCredentialIds=securityKeyAllowedCredentialIds | ||
challenge=securityKeyChallenge | ||
showSecurityKey=showSecurityKey | ||
showSecondFactor=showSecondFactor | ||
secondFactorMethod=secondFactorMethod | ||
otherMethodAllowed=otherMethodAllowed | ||
action=(action "authenticateSecurityKey")}} | ||
{{/security-key-form}} | ||
{{else}} | ||
{{second-factor-input value=secondFactorToken inputId="second-factor-confirmation" secondFactorMethod=secondFactorMethod backupEnabled=backupEnabled}} | ||
{{/if}} | ||
{{/second-factor-form}} | ||
|
||
{{#unless showSecurityKey}} | ||
<div class="modal-footer"> | ||
{{d-button | ||
action=(action "authenticate") | ||
icon="shield-alt" | ||
label="admin.user.grant_admin" | ||
disabled=disabled | ||
class="btn btn-primary"}} | ||
</div> | ||
{{/unless}} | ||
{{/d-modal-body}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters