Skip to content

Commit 85efa2d

Browse files
authored
ciba and email and sms gateways for delivery (#36)
1 parent 75f976b commit 85efa2d

File tree

6 files changed

+120
-4
lines changed

6 files changed

+120
-4
lines changed

auth0/actions/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
all: dist/silent-account-linking.js dist/post-login-claims.js dist/render-privacy-policy-form.js dist/mfa-when-enrolled.js
1+
all: dist/silent-account-linking.js dist/post-login-claims.js dist/render-privacy-policy-form.js dist/mfa-when-enrolled.js dist/sms-to-slack.js
22

33
dist/%.js: %.ts
44
npm run build

auth0/actions/sms-to-slack.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import {Event, CustomPhoneProviderAPI} from "@auth0/actions/custom-phone-provider/v1";
2+
3+
// noinspection JSUnusedLocalSymbols
4+
/**
5+
* Handler to be executed while sending an email notification
6+
* @param {Event} event - Details about the user and the context in which they are logging in.
7+
* @param {CustomPhoneProviderAPI} api - Methods and utilities to help change the behavior of sending a phone notification.
8+
*/
9+
exports.onExecuteCustomPhoneProvider = async (event: Event, api: CustomPhoneProviderAPI) => {
10+
const SLACK_WEBHOOK_URL = event.secrets.SLACK_WEBHOOK_URL;
11+
12+
console.log(`onExecuteCustomPhoneProvider event: ${JSON.stringify(event)}`);
13+
14+
const {message_type, as_text, recipient} = event.notification;
15+
const slackText = `Type ${message_type} \nRecipient: ${recipient} \nMessage: ${as_text}`;
16+
17+
const axios = require('axios');
18+
19+
// send to slack
20+
const {data} =
21+
await axios({
22+
method: 'post',
23+
url: `${SLACK_WEBHOOK_URL}`,
24+
data: {
25+
text: slackText
26+
},
27+
headers: {
28+
'Content-Type': 'application/json'
29+
},
30+
timeout: 5000 // 5 sec
31+
});
32+
33+
console.log(`response from slack: ${data}`);
34+
};

tf/02-donor-website.tf

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,15 @@ resource "auth0_user" "user1" {
3939
connection_name = data.auth0_connection.Username-Password-Authentication.name
4040
email = "user1@atko.email"
4141
password = "user1@atko.email"
42+
email_verified = true
4243
}
4344

4445
resource "auth0_user" "user2" {
45-
connection_name = data.auth0_connection.Username-Password-Authentication.name
46-
email = "user2@atko.email"
47-
password = "user2@atko.email"
46+
connection_name = data.auth0_connection.Username-Password-Authentication.name
47+
email = "user2@atko.email"
48+
password = "user2@atko.email"
4849
custom_domain_header = "id.${var.top_level_domain}"
50+
email_verified = true
4951
}
5052

5153

tf/03-social-login.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ resource "null_resource" "build_auth0_actions" {
4545
sal_acntlink_ts_hash = filesha1("${path.module}/../auth0/actions/silent-account-linking.ts")
4646
mfa_ts_hash = filesha1("${path.module}/../auth0/actions/mfa-when-enrolled.ts")
4747
form_ts_hash = filesha1("${path.module}/../auth0/actions/render-privacy-policy-form.ts")
48+
sms_to_slack_ts_hash = filesha1("${path.module}/../auth0/actions/sms-to-slack.ts")
4849
}
4950

5051
provisioner "local-exec" {

tf/12-ciba.tf

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
## Email Server
2+
resource "auth0_email_provider" "mailtrap" {
3+
name = "smtp"
4+
enabled = true
5+
default_from_address = "noreply@replate.dev"
6+
credentials {
7+
smtp_host = var.mailtrap_smtp_host
8+
smtp_port = var.mailtrap_smtp_port
9+
smtp_user = var.mailtrap_smtp_user
10+
smtp_pass = var.mailtrap_smtp_pass
11+
}
12+
}
13+
14+
resource "auth0_phone_provider" "custom_phone_provider" {
15+
name = "custom"
16+
disabled = false
17+
18+
configuration {
19+
delivery_methods = ["text"]
20+
}
21+
22+
credentials {}
23+
24+
depends_on = [
25+
auth0_action.sms_to_slack
26+
]
27+
}
28+
29+
resource "auth0_action" "sms_to_slack" {
30+
31+
depends_on = [null_resource.build_auth0_actions]
32+
33+
name = "SMS to Slack"
34+
runtime = "node22"
35+
deploy = true
36+
code = file("${path.module}/../auth0/actions/dist/sms-to-slack.js")
37+
38+
supported_triggers {
39+
id = "custom-phone-provider"
40+
version = "v1"
41+
}
42+
43+
dependencies {
44+
name = "axios"
45+
version = "1.7.9"
46+
}
47+
48+
secrets {
49+
name = "SLACK_WEBHOOK_URL"
50+
value = var.slack_webhook_url
51+
}
52+
}

tf/variables.tf

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,33 @@ variable "microsoft_client_secret" {
144144
sensitive = true
145145
}
146146

147+
## mailtrap
148+
variable "mailtrap_smtp_host" {
149+
type = string
150+
default = "sandbox.smtp.mailtrap.io"
151+
}
152+
153+
variable "mailtrap_smtp_port" {
154+
type = number
155+
default = 2525
156+
}
157+
158+
variable "mailtrap_smtp_user" {
159+
type = string
160+
}
161+
162+
variable "mailtrap_smtp_pass" {
163+
type = string
164+
sensitive = true
165+
}
166+
167+
# slack
168+
variable "slack_webhook_url" {
169+
type = string
170+
sensitive = true
171+
}
172+
173+
147174
## AoB
148175
variable "default-password" {
149176
type = string

0 commit comments

Comments
 (0)