feat: introduce twilio auth

This commit is contained in:
Ali BARIN
2021-10-27 20:04:08 +02:00
parent 72476ceb8b
commit 219d24495d
6 changed files with 297 additions and 2 deletions

View File

@@ -33,6 +33,7 @@
"nodemailer": "6.7.0",
"objection": "^2.2.17",
"pg": "^8.7.1",
"twilio": "3.70.0",
"twitch-js": "2.0.0-beta.42",
"twitter-api-v2": "1.6.0",
"winston": "^3.3.3"

View File

@@ -3,7 +3,7 @@
"key": "discord",
"iconUrl": "{BASE_URL}/apps/discord/assets/favicon.svg",
"docUrl": "https://automatisch.io/docs/discord",
"primaryColor": "2DAAE1",
"primaryColor": "5865f2",
"fields": [
{
"key": "oAuthRedirectUrl",

View File

@@ -0,0 +1,6 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
aria-label="Twilio" role="img"
viewBox="0 0 512 512"><rect
width="512" height="512"
rx="15%"
fill="#fff"/><g fill="#f22f46"><circle cx="256" cy="256" r="256"/><circle cx="256" cy="256" fill="#fff" r="188"/><circle cx="193" cy="193" r="53" id="c"/><use xlink:href="#c" x="126"/><use xlink:href="#c" y="126"/><use xlink:href="#c" x="126" y="126"/></g></svg>

After

Width:  |  Height:  |  Size: 438 B

View File

@@ -0,0 +1,37 @@
import TwilioApi from 'twilio';
import App from '../../models/app';
export default class Twilio {
client: any
connectionData: any
appData: any
constructor(connectionData: any) {
this.client = TwilioApi(connectionData.accountSid, connectionData.authToken);
this.connectionData = connectionData;
this.appData = App.findOneByKey('twilio');
}
async verifyCredentials() {
await this.verify();
return {
screenName: this.connectionData.accountSid
}
}
async verify() {
try {
await this.client.keys.list({ limit: 1 })
return true;
} catch(error) {
// Test credentials throw HTTP 403 and thus, we need to have an exception.
return error?.status === 403;
}
}
async isStillVerified() {
return this.verify();
}
}

View File

@@ -0,0 +1,120 @@
{
"name": "Twilio",
"key": "twilio",
"iconUrl": "{BASE_URL}/apps/twilio/assets/favicon.svg",
"docUrl": "https://automatisch.io/docs/twilio",
"primaryColor": "f22f46",
"fields": [
{
"key": "accountSid",
"label": "Account SID",
"type": "string",
"required": true,
"readOnly": false,
"value": null,
"placeholder": null,
"description": "Log into your Twilio account and find \"API Credentials\" on this page https://www.twilio.com/user/account/settings",
"docUrl": "https://automatisch.io/docs/twilio#host",
"clickToCopy": false
},
{
"key": "authToken",
"label": "Auth Token",
"type": "string",
"required": true,
"readOnly": false,
"value": null,
"placeholder": null,
"description": "Found directly below your Account SID.",
"docUrl": "https://automatisch.io/docs/twilio#username",
"clickToCopy": false
}
],
"authenticationSteps": [
{
"step": 1,
"type": "mutation",
"name": "createConnection",
"arguments": [
{
"name": "key",
"value": "{key}"
},
{
"name": "data",
"value": null,
"properties": [
{
"name": "accountSid",
"value": "{fields.accountSid}"
},
{
"name": "authToken",
"value": "{fields.authToken}"
}
]
}
]
},
{
"step": 2,
"type": "mutation",
"name": "verifyConnection",
"arguments": [
{
"name": "id",
"value": "{createConnection.id}"
}
]
}
],
"reconnectionSteps": [
{
"step": 1,
"type": "mutation",
"name": "resetConnection",
"arguments": [
{
"name": "id",
"value": "{connection.id}"
}
]
},
{
"step": 2,
"type": "mutation",
"name": "updateConnection",
"arguments": [
{
"name": "id",
"value": "{connection.id}"
},
{
"name": "data",
"value": null,
"properties": [
{
"name": "accountSid",
"value": "{fields.accountSid}"
},
{
"name": "authToken",
"value": "{fields.authToken}"
}
]
}
]
},
{
"step": 3,
"type": "mutation",
"name": "verifyConnection",
"arguments": [
{
"name": "id",
"value": "{connection.id}"
}
]
}
]
}