Skip to content

Commit

Permalink
A few small bugfixes related to email OTP
Browse files Browse the repository at this point in the history
  • Loading branch information
evert committed Jan 8, 2025
1 parent ba3f0a8 commit 84b08ea
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion schemas/authorization-challenge-request.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"maxLength": 6,
"pattern": "^[0-9]{6}$"
},
"email_opt_code": {
"email_otp_code": {
"type": "string",
"description": "A 6 digit one-time password sent to an email address.",
"minLength": 6,
Expand Down
2 changes: 1 addition & 1 deletion src/api-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export interface AuthorizationChallengeRequest {
/**
* A 6 digit one-time password sent to an email address.
*/
email_opt_code?: string;
email_otp_code?: string;
/**
* Ip address (ipv4 or ipv6) of the client making the request. For logging and anomaly detection.
*/
Expand Down
9 changes: 7 additions & 2 deletions src/login/challenge/email-otp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ export class LoginChallengeEmailOtp extends AbstractLoginChallenge<EmailOtpParam
return true;
} catch (err) {
if (err instanceof BadRequest) {
throw new A12nLoginChallengeError('Invalid or expired email_otp_code', 'email_otp_invalid');
await services.principalIdentity.sendOtpRequest(identity, this.ip);
throw new A12nLoginChallengeError(
'Invalid or expired email_otp_code',
'email_otp_invalid',
{ censored_email: censor(identity.uri) }
);
} else {
throw err;
}
Expand All @@ -66,7 +71,7 @@ export class LoginChallengeEmailOtp extends AbstractLoginChallenge<EmailOtpParam
*/
parametersContainsResponse(parameters: AuthorizationChallengeRequest): parameters is EmailOtpParameters & AuthorizationChallengeRequest {

return parameters.email_opt_code !== undefined;
return parameters.email_otp_code !== undefined;

}

Expand Down

0 comments on commit 84b08ea

Please sign in to comment.