Skip to content

Commit

Permalink
Adding support for SMS Blocking functions CLI (#7628)
Browse files Browse the repository at this point in the history
* Blocking function SMS

---------

Co-authored-by: Brian Li <blidd@google.com>
Co-authored-by: joehan <joehanley@google.com>
Co-authored-by: Mathusan Selvarajah <mathusans52@gmail.com>
  • Loading branch information
4 people authored Oct 17, 2024
1 parent b0f2478 commit 576dc21
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 7 deletions.
7 changes: 2 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
- Re-add a dialog to let users know TLS is being provisioned in App Hosting (#7595)
- Improve Firebase Data Connect postgres security by granting fine grained SQL privileges to the users the need it. (#7578)
- Remove `dataconnect:sql:migrate` command hard dependency on 'roles/cloudsql.admin'. (#7578)
- Add support for setting the encryption configuration of restored firestore databases (#7483)
- Added support for deploying `beforeEmailSent` blocking functions. (#6384)
- Add support for deploying `beforeEmailSent` blocking function. (#6384)
- Add support for `beforeSmsSent` auth blocking triggers. (#6733)
16 changes: 14 additions & 2 deletions src/deploy/functions/services/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ export class AuthBlockingService implements Service {
newConfig.triggers?.beforeSignIn?.functionUri !==
config.triggers?.beforeSignIn?.functionUri ||
newConfig.triggers?.beforeSendEmail?.functionUri !==
config.triggers?.beforeSendEmail?.functionUri
config.triggers?.beforeSendEmail?.functionUri ||
newConfig.triggers?.beforeSendSms?.functionUri !== config.triggers?.beforeSendSms?.functionUri
) {
return true;
}
Expand Down Expand Up @@ -99,6 +100,13 @@ export class AuthBlockingService implements Service {
functionUri: endpoint.uri!,
},
};
} else if (endpoint.blockingTrigger.eventType === events.v1.BEFORE_SEND_SMS_EVENT) {
newBlockingConfig.triggers = {
...newBlockingConfig.triggers,
beforeSendSms: {
functionUri: endpoint.uri!,
},
};
} else {
throw new FirebaseError(
`Received invalid blocking trigger event type ${endpoint.blockingTrigger.eventType}`,
Expand Down Expand Up @@ -136,7 +144,8 @@ export class AuthBlockingService implements Service {
if (
endpoint.uri !== blockingConfig.triggers?.beforeCreate?.functionUri &&
endpoint.uri !== blockingConfig.triggers?.beforeSignIn?.functionUri &&
endpoint.uri !== blockingConfig.triggers?.beforeSendEmail?.functionUri
endpoint.uri !== blockingConfig.triggers?.beforeSendEmail?.functionUri &&
endpoint.uri !== blockingConfig.triggers?.beforeSendSms?.functionUri
) {
return;
}
Expand All @@ -153,6 +162,9 @@ export class AuthBlockingService implements Service {
if (endpoint.uri === blockingConfig.triggers?.beforeSendEmail?.functionUri) {
delete blockingConfig.triggers?.beforeSendEmail;
}
if (endpoint.uri === blockingConfig.triggers?.beforeSendSms?.functionUri) {
delete blockingConfig.triggers?.beforeSendSms;
}

await identityPlatform.setBlockingFunctionsConfig(endpoint.project, blockingConfig);
}
Expand Down
1 change: 1 addition & 0 deletions src/deploy/functions/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ const EVENT_SERVICE_MAPPING: Record<events.Event, Service> = {
"providers/cloud.auth/eventTypes/user.beforeCreate": authBlockingService,
"providers/cloud.auth/eventTypes/user.beforeSignIn": authBlockingService,
"providers/cloud.auth/eventTypes/user.beforeSendEmail": authBlockingService,
"providers/cloud.auth/eventTypes/user.beforeSendSms": authBlockingService,
"google.firebase.database.ref.v1.written": databaseService,
"google.firebase.database.ref.v1.created": databaseService,
"google.firebase.database.ref.v1.updated": databaseService,
Expand Down
2 changes: 2 additions & 0 deletions src/functions/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ export const BLOCKING_LABEL_KEY_TO_EVENT: Record<string, (typeof AUTH_BLOCKING_E
"before-create": "providers/cloud.auth/eventTypes/user.beforeCreate",
"before-sign-in": "providers/cloud.auth/eventTypes/user.beforeSignIn",
"before-send-email": "providers/cloud.auth/eventTypes/user.beforeSendEmail",
"before-send-sms": "providers/cloud.auth/eventTypes/user.beforeSendSms",
};

export const BLOCKING_EVENT_TO_LABEL_KEY: Record<(typeof AUTH_BLOCKING_EVENTS)[number], string> = {
"providers/cloud.auth/eventTypes/user.beforeCreate": "before-create",
"providers/cloud.auth/eventTypes/user.beforeSignIn": "before-sign-in",
"providers/cloud.auth/eventTypes/user.beforeSendEmail": "before-send-email",
"providers/cloud.auth/eventTypes/user.beforeSendSms": "before-send-sms",
};
3 changes: 3 additions & 0 deletions src/functions/events/v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ export const BEFORE_SIGN_IN_EVENT = "providers/cloud.auth/eventTypes/user.before

export const BEFORE_SEND_EMAIL_EVENT = "providers/cloud.auth/eventTypes/user.beforeSendEmail";

export const BEFORE_SEND_SMS_EVENT = "providers/cloud.auth/eventTypes/user.beforeSendSms";

export const AUTH_BLOCKING_EVENTS = [
BEFORE_CREATE_EVENT,
BEFORE_SIGN_IN_EVENT,
BEFORE_SEND_EMAIL_EVENT,
BEFORE_SEND_SMS_EVENT,
] as const;

export type Event = (typeof AUTH_BLOCKING_EVENTS)[number];
1 change: 1 addition & 0 deletions src/gcp/identityPlatform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export interface BlockingFunctionsConfig {
beforeCreate?: BlockingFunctionsEventDetails;
beforeSignIn?: BlockingFunctionsEventDetails;
beforeSendEmail?: BlockingFunctionsEventDetails;
beforeSendSms?: BlockingFunctionsEventDetails;
};
forwardInboundCredentials?: BlockingFunctionsOptions;
}
Expand Down

0 comments on commit 576dc21

Please sign in to comment.