feat(slack): use oauth2 authentication flow

This commit is contained in:
Ali BARIN
2022-11-02 20:24:25 +01:00
parent e740d4fe25
commit f057501611
4 changed files with 241 additions and 25 deletions

View File

@@ -1,10 +1,21 @@
import { TBeforeRequest } from '@automatisch/types';
const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
if (requestConfig.headers && $.auth.data?.accessToken) {
requestConfig.headers.Authorization = `Bearer ${$.auth.data.accessToken}`;
const authData = $.auth.data;
if (
requestConfig.headers
&& authData?.userAccessToken
&& authData?.botAccessToken
) {
if (requestConfig.additionalProperties?.sendAsBot) {
requestConfig.headers.Authorization = `Bearer ${authData.botAccessToken}`;
} else {
requestConfig.headers.Authorization = `Bearer ${authData.userAccessToken}`;
}
}
requestConfig.headers['Content-Type'] = requestConfig.headers['Content-Type'] || 'application/json; charset=utf-8';
return requestConfig;
};