-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add beforeEmailSent and beforeSmsSent trigger types (#1621)
* add support for beforeEmail trigger * remove opts from beforeemail & decode user record only for beforeCreate and beforeSignIn * fix unit tests * add changelog * add comment to authblockingevent type * rebase * rebase * Add beforeSmsSent blocking functions trigger * adding spec.ts changes * lint * rebase * rebase * changelog * remove duplicate unit test * update EmailType to EMAIL_SIGN_IN | PASSWORD_RESET * api comment fixes * minor docstring fix --------- Co-authored-by: Pragati <[email protected]>
- Loading branch information
1 parent
6b02fd3
commit 827ba0e
Showing
7 changed files
with
651 additions
and
129 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- Add support for beforeSmsSent auth blocking triggers. (#1589) |
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 |
---|---|---|
|
@@ -528,6 +528,8 @@ describe("identity", () => { | |
userAgent: "USER_AGENT", | ||
eventId: "EVENT_ID", | ||
eventType: EVENT, | ||
emailType: undefined, | ||
smsType: undefined, | ||
authType: "UNAUTHENTICATED", | ||
resource: { | ||
service: "identitytoolkit.googleapis.com", | ||
|
@@ -540,6 +542,8 @@ describe("identity", () => { | |
username: undefined, | ||
isNewUser: false, | ||
recaptchaScore: TEST_RECAPTCHA_SCORE, | ||
email: undefined, | ||
phoneNumber: undefined, | ||
}, | ||
credential: null, | ||
params: {}, | ||
|
@@ -577,6 +581,8 @@ describe("identity", () => { | |
userAgent: "USER_AGENT", | ||
eventId: "EVENT_ID", | ||
eventType: "providers/cloud.auth/eventTypes/user.beforeSignIn:password", | ||
emailType: undefined, | ||
smsType: undefined, | ||
authType: "UNAUTHENTICATED", | ||
resource: { | ||
service: "identitytoolkit.googleapis.com", | ||
|
@@ -589,6 +595,8 @@ describe("identity", () => { | |
username: undefined, | ||
isNewUser: false, | ||
recaptchaScore: TEST_RECAPTCHA_SCORE, | ||
email: undefined, | ||
phoneNumber: undefined, | ||
}, | ||
credential: { | ||
claims: undefined, | ||
|
@@ -663,6 +671,8 @@ describe("identity", () => { | |
userAgent: "USER_AGENT", | ||
eventId: "EVENT_ID", | ||
eventType: "providers/cloud.auth/eventTypes/user.beforeCreate:oidc.provider", | ||
emailType: undefined, | ||
smsType: undefined, | ||
authType: "USER", | ||
resource: { | ||
service: "identitytoolkit.googleapis.com", | ||
|
@@ -675,6 +685,8 @@ describe("identity", () => { | |
profile: rawUserInfo, | ||
isNewUser: true, | ||
recaptchaScore: TEST_RECAPTCHA_SCORE, | ||
email: undefined, | ||
phoneNumber: undefined, | ||
}, | ||
credential: { | ||
claims: undefined, | ||
|
@@ -691,6 +703,98 @@ describe("identity", () => { | |
|
||
expect(identity.parseAuthEventContext(decodedJwt, "project-id", time)).to.deep.equal(context); | ||
}); | ||
|
||
it("should parse a beforeSendEmail event", () => { | ||
const time = now.getTime(); | ||
const decodedJwt = { | ||
iss: "https://securetoken.google.com/project_id", | ||
aud: "https://us-east1-project_id.cloudfunctions.net/function-1", | ||
iat: 1, | ||
exp: 60 * 60 + 1, | ||
event_id: "EVENT_ID", | ||
event_type: "beforeSendEmail", | ||
user_agent: "USER_AGENT", | ||
ip_address: "1.2.3.4", | ||
locale: "en", | ||
recaptcha_score: TEST_RECAPTCHA_SCORE, | ||
email_type: "RESET_PASSWORD", | ||
email: "[email protected]", | ||
}; | ||
const context = { | ||
locale: "en", | ||
ipAddress: "1.2.3.4", | ||
userAgent: "USER_AGENT", | ||
eventId: "EVENT_ID", | ||
eventType: "providers/cloud.auth/eventTypes/user.beforeSendEmail", | ||
emailType: "RESET_PASSWORD", | ||
smsType: undefined, | ||
authType: "UNAUTHENTICATED", | ||
resource: { | ||
service: "identitytoolkit.googleapis.com", | ||
name: "projects/project-id", | ||
}, | ||
timestamp: new Date(1000).toUTCString(), | ||
additionalUserInfo: { | ||
isNewUser: false, | ||
profile: undefined, | ||
providerId: undefined, | ||
username: undefined, | ||
recaptchaScore: TEST_RECAPTCHA_SCORE, | ||
email: "[email protected]", | ||
phoneNumber: undefined, | ||
}, | ||
credential: null, | ||
params: {}, | ||
}; | ||
|
||
expect(identity.parseAuthEventContext(decodedJwt, "project-id", time)).to.deep.equal(context); | ||
}); | ||
|
||
it("should parse a beforeSendSms event", () => { | ||
const time = now.getTime(); | ||
const decodedJwt = { | ||
iss: "https://securetoken.google.com/project_id", | ||
aud: "https://us-east1-project_id.cloudfunctions.net/function-1", | ||
iat: 1, | ||
exp: 60 * 60 + 1, | ||
event_id: "EVENT_ID", | ||
event_type: "beforeSendSms", | ||
user_agent: "USER_AGENT", | ||
ip_address: "1.2.3.4", | ||
locale: "en", | ||
recaptcha_score: TEST_RECAPTCHA_SCORE, | ||
sms_type: "SIGN_IN_OR_SIGN_UP", | ||
phone_number: "+11234567890", | ||
}; | ||
const context = { | ||
locale: "en", | ||
ipAddress: "1.2.3.4", | ||
userAgent: "USER_AGENT", | ||
eventId: "EVENT_ID", | ||
eventType: "providers/cloud.auth/eventTypes/user.beforeSendSms", | ||
emailType: undefined, | ||
smsType: "SIGN_IN_OR_SIGN_UP", | ||
authType: "UNAUTHENTICATED", | ||
resource: { | ||
service: "identitytoolkit.googleapis.com", | ||
name: "projects/project-id", | ||
}, | ||
timestamp: new Date(1000).toUTCString(), | ||
additionalUserInfo: { | ||
isNewUser: false, | ||
profile: undefined, | ||
providerId: undefined, | ||
username: undefined, | ||
recaptchaScore: TEST_RECAPTCHA_SCORE, | ||
email: undefined, | ||
phoneNumber: "+11234567890", | ||
}, | ||
credential: null, | ||
params: {}, | ||
}; | ||
|
||
expect(identity.parseAuthEventContext(decodedJwt, "project-id", time)).to.deep.equal(context); | ||
}); | ||
}); | ||
|
||
describe("validateAuthResponse", () => { | ||
|
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
Oops, something went wrong.