mirror of
https://github.com/discourse/discourse.git
synced 2025-02-27 16:06:10 +00:00
Check webauthn support when registering security keys (#8146)
This commit is contained in:
parent
91dd6aacfb
commit
61868e50cb
@ -1,5 +1,9 @@
|
|||||||
import ModalFunctionality from "discourse/mixins/modal-functionality";
|
import ModalFunctionality from "discourse/mixins/modal-functionality";
|
||||||
import { bufferToBase64, stringToBuffer } from "discourse/lib/webauthn";
|
import {
|
||||||
|
bufferToBase64,
|
||||||
|
stringToBuffer,
|
||||||
|
isWebauthnSupported
|
||||||
|
} from "discourse/lib/webauthn";
|
||||||
|
|
||||||
// model for this controller is user.js.es6
|
// model for this controller is user.js.es6
|
||||||
export default Ember.Controller.extend(ModalFunctionality, {
|
export default Ember.Controller.extend(ModalFunctionality, {
|
||||||
@ -11,7 +15,8 @@ export default Ember.Controller.extend(ModalFunctionality, {
|
|||||||
this.setProperties({
|
this.setProperties({
|
||||||
errorMessage: null,
|
errorMessage: null,
|
||||||
loading: true,
|
loading: true,
|
||||||
securityKeyName: I18n.t("user.second_factor.security_key.default_name")
|
securityKeyName: I18n.t("user.second_factor.security_key.default_name"),
|
||||||
|
webauthnUnsupported: !isWebauthnSupported()
|
||||||
});
|
});
|
||||||
|
|
||||||
this.model
|
this.model
|
||||||
@ -23,7 +28,9 @@ export default Ember.Controller.extend(ModalFunctionality, {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.setProperties({
|
this.setProperties({
|
||||||
errorMessage: null,
|
errorMessage: isWebauthnSupported()
|
||||||
|
? null
|
||||||
|
: I18n.t("login.security_key_support_missing_error"),
|
||||||
loading: false,
|
loading: false,
|
||||||
challenge: response.challenge,
|
challenge: response.challenge,
|
||||||
relayingParty: {
|
relayingParty: {
|
||||||
|
@ -11,13 +11,17 @@ export function bufferToBase64(buffer) {
|
|||||||
return btoa(String.fromCharCode(...new Uint8Array(buffer)));
|
return btoa(String.fromCharCode(...new Uint8Array(buffer)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isWebauthnSupported() {
|
||||||
|
return typeof PublicKeyCredential !== "undefined";
|
||||||
|
}
|
||||||
|
|
||||||
export function getWebauthnCredential(
|
export function getWebauthnCredential(
|
||||||
challenge,
|
challenge,
|
||||||
allowedCredentialIds,
|
allowedCredentialIds,
|
||||||
successCallback,
|
successCallback,
|
||||||
errorCallback
|
errorCallback
|
||||||
) {
|
) {
|
||||||
if (typeof PublicKeyCredential === "undefined") {
|
if (!isWebauthnSupported()) {
|
||||||
return errorCallback(I18n.t("login.security_key_support_missing_error"));
|
return errorCallback(I18n.t("login.security_key_support_missing_error"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,9 +22,11 @@
|
|||||||
|
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
{{d-button action=(action "registerSecurityKey")
|
{{#unless webauthnUnsupported}}
|
||||||
class="btn btn-primary add-totp"
|
{{d-button action=(action "registerSecurityKey")
|
||||||
label="user.second_factor.security_key.register"}}
|
class="btn btn-primary add-totp"
|
||||||
|
label="user.second_factor.security_key.register"}}
|
||||||
|
{{/unless}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{/conditional-loading-spinner}}
|
{{/conditional-loading-spinner}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user