Skip to content
This repository was archived by the owner on Jun 25, 2024. It is now read-only.

Commit fb795cb

Browse files
author
Billy Clark
committed
u2f error messages were a little to techy
1 parent 6af823c commit fb795cb

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

dictionaries/mfa.definition.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,24 @@
8484
"fr": "TODO",
8585
"ko": "TODO"
8686
},
87+
"u2f_error_unknown": {
88+
"en": "Something went wrong with that request, unable to verify at this time.",
89+
"es": "TODO",
90+
"fr": "TODO",
91+
"ko": "TODO"
92+
},
93+
"u2f_error_wrong_key": {
94+
"en": "This may not be the correct key for this site.",
95+
"es": "TODO",
96+
"fr": "TODO",
97+
"ko": "TODO"
98+
},
99+
"u2f_error_timeout": {
100+
"en": "That took a little too long, check to make sure your key is inserted right-side up.",
101+
"es": "TODO",
102+
"fr": "TODO",
103+
"ko": "TODO"
104+
},
87105
"shield_icon": {
88106
"en": "Shield icon",
89107
"es": "TODO",

themes/material/mfa/prompt-for-mfa-u2f.php

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,25 @@ function verifyU2f() {
3030
}
3131

3232
function handleU2fResponse(u2fResponse) {
33-
if (u2fResponse.errorCode && u2fResponse.errorCode != 0) {
33+
if (isU2fError(u2fResponse)) {
3434
return handleError(u2fResponse);
3535
}
3636

3737
submitForm(u2fResponse);
3838
}
3939

40-
function handleError(u2fResponse) {
41-
//TODO: need to consider natural language for these errors (as well as translations)
42-
var message = u2fResponse.errorMessage ||
43-
Object.keys(u2f.ErrorCodes)[u2fResponse.errorCode];
40+
/**
41+
* @param {u2f.Error|u2f.SignResponse=} response
42+
*/
43+
function isU2fError (response) {
44+
return !!response.errorCode;
45+
}
46+
47+
/**
48+
* @param {u2f.Error=} error
49+
*/
50+
function handleError(error) {
51+
var message = error.errorMessage || createMessage(error.errorCode);
4452

4553
var errorNode = document.querySelector('p.error');
4654

@@ -50,6 +58,20 @@ function handleError(u2fResponse) {
5058
offerRetry();
5159
}
5260

61+
/**
62+
* https://developers.yubico.com/U2F/Libraries/Client_error_codes.html
63+
* @param {u2f.ErrorCodes=} code
64+
*/
65+
function createMessage (code) {
66+
switch (code) {
67+
case 1:
68+
case 2:
69+
case 3: return '<?= $this->t('{material:mfa:u2f_error_unknown}') ?>';
70+
case 4: return '<?= $this->t('{material:mfa:u2f_error_wrong_key}') ?>';
71+
case 5: return '<?= $this->t('{material:mfa:u2f_error_timeout}') ?>';
72+
}
73+
}
74+
5375
function offerRetry() {
5476
var retryButton = document.querySelector('.mdl-button.mdl-color-text--red');
5577

0 commit comments

Comments
 (0)