chore: Extract authentication logic of the apps to their own classes

This commit is contained in:
Faruk AYDIN
2021-11-18 12:54:56 +01:00
committed by Ömer Faruk Aydın
parent 6b1dee053f
commit 46321f19f4
23 changed files with 707 additions and 617 deletions

View File

@@ -1,37 +1,9 @@
import TwilioApi from 'twilio';
import App from '../../models/app';
import Authentication from './authentication';
export default class Twilio {
client: any
connectionData: any
appData: any
authenticationClient: 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();
this.authenticationClient = new Authentication(connectionData);
}
}