feat: Implement slack authentication
This commit is contained in:
committed by
Ömer Faruk Aydın
parent
2218ffd790
commit
f8c7b85682
39
packages/backend/src/apps/slack/authentication.ts
Normal file
39
packages/backend/src/apps/slack/authentication.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import type { IAuthentication, IApp, IJSONObject } from '@automatisch/types';
|
||||
import { WebClient } from '@slack/web-api';
|
||||
|
||||
export default class Authentication implements IAuthentication {
|
||||
appData: IApp;
|
||||
connectionData: IJSONObject;
|
||||
client: WebClient;
|
||||
|
||||
constructor(appData: IApp, connectionData: IJSONObject) {
|
||||
this.client = new WebClient();
|
||||
|
||||
this.connectionData = connectionData;
|
||||
this.appData = appData;
|
||||
}
|
||||
|
||||
async verifyCredentials() {
|
||||
const { bot_id: botId, user: screenName } = await this.client.auth.test({
|
||||
token: this.connectionData.accessToken as string,
|
||||
});
|
||||
|
||||
return {
|
||||
botId,
|
||||
screenName,
|
||||
token: this.connectionData.accessToken,
|
||||
};
|
||||
}
|
||||
|
||||
async isStillVerified() {
|
||||
try {
|
||||
await this.client.auth.test({
|
||||
token: this.connectionData.accessToken as string,
|
||||
});
|
||||
|
||||
return true;
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user