Merge pull request #342 from automatisch/refactor/use-http-client-for-typeform-auth

refactor: Use http client to authenticate typeform
This commit is contained in:
Ömer Faruk Aydın
2022-07-16 00:57:23 +03:00
committed by GitHub
2 changed files with 13 additions and 5 deletions

View File

@@ -5,14 +5,12 @@ import type {
IJSONObject,
} from '@automatisch/types';
import { URLSearchParams } from 'url';
import axios, { AxiosInstance } from 'axios';
import HttpClient from '../../helpers/http-client';
export default class Authentication implements IAuthentication {
appData: IApp;
connectionData: IJSONObject;
client: AxiosInstance = axios.create({
baseURL: 'https://api.typeform.com',
});
client: HttpClient;
scope: string[] = [
'forms:read',
@@ -27,6 +25,7 @@ export default class Authentication implements IAuthentication {
constructor(appData: IApp, connectionData: IJSONObject) {
this.connectionData = connectionData;
this.appData = appData;
this.client = new HttpClient({ baseURL: 'https://api.typeform.com' });
}
get oauthRedirectUrl() {

View File

@@ -1,5 +1,6 @@
import Context from '../../types/express/context';
import App from '../../models/app';
import axios from 'axios';
type Params = {
input: {
@@ -22,11 +23,19 @@ const createAuthData = async (
const appClass = (await import(`../../apps/${connection.key}`)).default;
const appData = App.findOneByKey(connection.key);
if (!connection.formattedData) { return null; }
if (!connection.formattedData) {
return null;
}
const appInstance = new appClass(appData, connection.formattedData);
const authLink = await appInstance.authenticationClient.createAuthData();
try {
await axios.get(authLink.url);
} catch (error) {
throw new Error('Error occured while creating authorization URL!');
}
await connection.$query().patch({
formattedData: {
...connection.formattedData,