chore: Adjust authentication classes to have similar structure
This commit is contained in:

committed by
Ömer Faruk Aydın

parent
d06f21c927
commit
cdc6168ff4
@@ -3,14 +3,14 @@ import axios, { AxiosInstance } from 'axios';
|
|||||||
import Field from '../../types/field';
|
import Field from '../../types/field';
|
||||||
|
|
||||||
export default class Authentication {
|
export default class Authentication {
|
||||||
client?: any;
|
|
||||||
connectionData: any;
|
|
||||||
appData: any;
|
appData: any;
|
||||||
scope: string[] = ['identify', 'email'];
|
connectionData: any;
|
||||||
httpClient: AxiosInstance = axios.create({
|
client: AxiosInstance = axios.create({
|
||||||
baseURL: 'https://discord.com/api/',
|
baseURL: 'https://discord.com/api/',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
scope: string[] = ['identify', 'email'];
|
||||||
|
|
||||||
constructor(appData: any, connectionData: any) {
|
constructor(appData: any, connectionData: any) {
|
||||||
this.appData = appData;
|
this.appData = appData;
|
||||||
this.connectionData = connectionData;
|
this.connectionData = connectionData;
|
||||||
@@ -45,7 +45,7 @@ export default class Authentication {
|
|||||||
code: this.connectionData.oauthVerifier,
|
code: this.connectionData.oauthVerifier,
|
||||||
grant_type: 'authorization_code',
|
grant_type: 'authorization_code',
|
||||||
});
|
});
|
||||||
const { data: verifiedCredentials }: any = await this.httpClient.post(
|
const { data: verifiedCredentials }: any = await this.client.post(
|
||||||
'/oauth2/token',
|
'/oauth2/token',
|
||||||
params.toString()
|
params.toString()
|
||||||
);
|
);
|
||||||
@@ -58,7 +58,7 @@ export default class Authentication {
|
|||||||
token_type: tokenType,
|
token_type: tokenType,
|
||||||
} = verifiedCredentials;
|
} = verifiedCredentials;
|
||||||
|
|
||||||
const { data: user }: any = await this.httpClient.get('/users/@me', {
|
const { data: user }: any = await this.client.get('/users/@me', {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `${tokenType} ${accessToken}`,
|
Authorization: `${tokenType} ${accessToken}`,
|
||||||
},
|
},
|
||||||
@@ -80,7 +80,7 @@ export default class Authentication {
|
|||||||
|
|
||||||
async isStillVerified() {
|
async isStillVerified() {
|
||||||
try {
|
try {
|
||||||
await this.httpClient.get('/users/@me', {
|
await this.client.get('/users/@me', {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `${this.connectionData.tokenType} ${this.connectionData.accessToken}`,
|
Authorization: `${this.connectionData.tokenType} ${this.connectionData.accessToken}`,
|
||||||
},
|
},
|
||||||
|
@@ -2,9 +2,9 @@ import { google as GoogleApi } from 'googleapis';
|
|||||||
import Field from '../../types/field';
|
import Field from '../../types/field';
|
||||||
|
|
||||||
export default class Authentication {
|
export default class Authentication {
|
||||||
oauthClient: any;
|
|
||||||
connectionData: any;
|
|
||||||
appData: any;
|
appData: any;
|
||||||
|
connectionData: any;
|
||||||
|
client: any;
|
||||||
|
|
||||||
scopes: string[] = [
|
scopes: string[] = [
|
||||||
'https://www.googleapis.com/auth/datastore',
|
'https://www.googleapis.com/auth/datastore',
|
||||||
@@ -17,13 +17,13 @@ export default class Authentication {
|
|||||||
this.appData = appData;
|
this.appData = appData;
|
||||||
this.connectionData = connectionData;
|
this.connectionData = connectionData;
|
||||||
|
|
||||||
this.oauthClient = new GoogleApi.auth.OAuth2(
|
this.client = new GoogleApi.auth.OAuth2(
|
||||||
connectionData.consumerKey,
|
connectionData.consumerKey,
|
||||||
connectionData.consumerSecret,
|
connectionData.consumerSecret,
|
||||||
this.oauthRedirectUrl
|
this.oauthRedirectUrl
|
||||||
);
|
);
|
||||||
|
|
||||||
GoogleApi.options({ auth: this.oauthClient });
|
GoogleApi.options({ auth: this.client });
|
||||||
}
|
}
|
||||||
|
|
||||||
get oauthRedirectUrl() {
|
get oauthRedirectUrl() {
|
||||||
@@ -33,7 +33,7 @@ export default class Authentication {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async createAuthData() {
|
async createAuthData() {
|
||||||
const url = this.oauthClient.generateAuthUrl({
|
const url = this.client.generateAuthUrl({
|
||||||
access_type: 'offline',
|
access_type: 'offline',
|
||||||
scope: this.scopes,
|
scope: this.scopes,
|
||||||
});
|
});
|
||||||
@@ -42,10 +42,10 @@ export default class Authentication {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async verifyCredentials() {
|
async verifyCredentials() {
|
||||||
const { tokens } = await this.oauthClient.getToken(
|
const { tokens } = await this.client.getToken(
|
||||||
this.connectionData.oauthVerifier
|
this.connectionData.oauthVerifier
|
||||||
);
|
);
|
||||||
this.oauthClient.setCredentials(tokens);
|
this.client.setCredentials(tokens);
|
||||||
|
|
||||||
const people = GoogleApi.people('v1');
|
const people = GoogleApi.people('v1');
|
||||||
|
|
||||||
@@ -74,7 +74,7 @@ export default class Authentication {
|
|||||||
|
|
||||||
async isStillVerified() {
|
async isStillVerified() {
|
||||||
try {
|
try {
|
||||||
await this.oauthClient.getTokenInfo(this.connectionData.accessToken);
|
await this.client.getTokenInfo(this.connectionData.accessToken);
|
||||||
return true;
|
return true;
|
||||||
} catch {
|
} catch {
|
||||||
return false;
|
return false;
|
||||||
|
@@ -2,10 +2,10 @@ import FlickrApi from 'flickr-sdk';
|
|||||||
import Field from '../../types/field';
|
import Field from '../../types/field';
|
||||||
|
|
||||||
export default class Authentication {
|
export default class Authentication {
|
||||||
oauthClient: any;
|
|
||||||
client: any;
|
|
||||||
connectionData: any;
|
|
||||||
appData: any;
|
appData: any;
|
||||||
|
connectionData: any;
|
||||||
|
client: any;
|
||||||
|
oauthClient: any;
|
||||||
|
|
||||||
constructor(appData: any, connectionData: any) {
|
constructor(appData: any, connectionData: any) {
|
||||||
this.oauthClient = new FlickrApi.OAuth(
|
this.oauthClient = new FlickrApi.OAuth(
|
||||||
|
@@ -6,8 +6,8 @@ import {
|
|||||||
import Field from '../../types/field';
|
import Field from '../../types/field';
|
||||||
|
|
||||||
export default class Authentication {
|
export default class Authentication {
|
||||||
connectionData: any;
|
|
||||||
appData: any;
|
appData: any;
|
||||||
|
connectionData: any;
|
||||||
scopes: string[] = ['repo'];
|
scopes: string[] = ['repo'];
|
||||||
|
|
||||||
constructor(appData: any, connectionData: any) {
|
constructor(appData: any, connectionData: any) {
|
||||||
|
@@ -1,9 +1,9 @@
|
|||||||
import { Client } from 'pg';
|
import { Client } from 'pg';
|
||||||
|
|
||||||
export default class Authentication {
|
export default class Authentication {
|
||||||
client: any;
|
|
||||||
connectionData: any;
|
|
||||||
appData: any;
|
appData: any;
|
||||||
|
connectionData: any;
|
||||||
|
client: any;
|
||||||
|
|
||||||
constructor(appData: any, connectionData: any) {
|
constructor(appData: any, connectionData: any) {
|
||||||
this.client = new Client({
|
this.client = new Client({
|
||||||
|
@@ -1,9 +1,9 @@
|
|||||||
import nodemailer from 'nodemailer';
|
import nodemailer from 'nodemailer';
|
||||||
|
|
||||||
export default class Authentication {
|
export default class Authentication {
|
||||||
client: any;
|
|
||||||
connectionData: any;
|
|
||||||
appData: any;
|
appData: any;
|
||||||
|
connectionData: any;
|
||||||
|
client: any;
|
||||||
|
|
||||||
constructor(appData: any, connectionData: any) {
|
constructor(appData: any, connectionData: any) {
|
||||||
this.client = nodemailer.createTransport({
|
this.client = nodemailer.createTransport({
|
||||||
|
@@ -1,9 +1,9 @@
|
|||||||
import TwilioApi from 'twilio';
|
import TwilioApi from 'twilio';
|
||||||
|
|
||||||
export default class Authentication {
|
export default class Authentication {
|
||||||
client: any;
|
|
||||||
connectionData: any;
|
|
||||||
appData: any;
|
appData: any;
|
||||||
|
connectionData: any;
|
||||||
|
client: any;
|
||||||
|
|
||||||
constructor(appData: any, connectionData: any) {
|
constructor(appData: any, connectionData: any) {
|
||||||
this.client = TwilioApi(
|
this.client = TwilioApi(
|
||||||
|
@@ -10,9 +10,9 @@ type TwitchTokenResponse = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default class Authentication {
|
export default class Authentication {
|
||||||
client: any;
|
|
||||||
connectionData: any;
|
|
||||||
appData: any;
|
appData: any;
|
||||||
|
connectionData: any;
|
||||||
|
client: any;
|
||||||
|
|
||||||
constructor(appData: any, connectionData: any) {
|
constructor(appData: any, connectionData: any) {
|
||||||
this.connectionData = connectionData;
|
this.connectionData = connectionData;
|
||||||
|
@@ -2,9 +2,9 @@ import TwitterApi from 'twitter-api-v2';
|
|||||||
import Field from '../../types/field';
|
import Field from '../../types/field';
|
||||||
|
|
||||||
export default class Authentication {
|
export default class Authentication {
|
||||||
client: any;
|
|
||||||
connectionData: any;
|
|
||||||
appData: any;
|
appData: any;
|
||||||
|
connectionData: any;
|
||||||
|
client: any;
|
||||||
|
|
||||||
constructor(appData: any, connectionData: any) {
|
constructor(appData: any, connectionData: any) {
|
||||||
this.appData = appData;
|
this.appData = appData;
|
||||||
|
@@ -3,9 +3,12 @@ import axios, { AxiosInstance } from 'axios';
|
|||||||
import Field from '../../types/field';
|
import Field from '../../types/field';
|
||||||
|
|
||||||
export default class Authentication {
|
export default class Authentication {
|
||||||
client?: any;
|
|
||||||
connectionData: any;
|
|
||||||
appData: any;
|
appData: any;
|
||||||
|
connectionData: any;
|
||||||
|
client: AxiosInstance = axios.create({
|
||||||
|
baseURL: 'https://api.typeform.com',
|
||||||
|
});
|
||||||
|
|
||||||
scope: string[] = [
|
scope: string[] = [
|
||||||
'forms:read',
|
'forms:read',
|
||||||
'forms:write',
|
'forms:write',
|
||||||
@@ -15,9 +18,6 @@ export default class Authentication {
|
|||||||
'accounts:read',
|
'accounts:read',
|
||||||
'workspaces:read',
|
'workspaces:read',
|
||||||
];
|
];
|
||||||
httpClient: AxiosInstance = axios.create({
|
|
||||||
baseURL: 'https://api.typeform.com',
|
|
||||||
});
|
|
||||||
|
|
||||||
constructor(appData: any, connectionData: any) {
|
constructor(appData: any, connectionData: any) {
|
||||||
this.connectionData = connectionData;
|
this.connectionData = connectionData;
|
||||||
@@ -51,7 +51,7 @@ export default class Authentication {
|
|||||||
redirect_uri: this.oauthRedirectUrl,
|
redirect_uri: this.oauthRedirectUrl,
|
||||||
});
|
});
|
||||||
|
|
||||||
const { data: verifiedCredentials }: any = await this.httpClient.post(
|
const { data: verifiedCredentials }: any = await this.client.post(
|
||||||
'/oauth/token',
|
'/oauth/token',
|
||||||
params.toString()
|
params.toString()
|
||||||
);
|
);
|
||||||
@@ -62,7 +62,7 @@ export default class Authentication {
|
|||||||
token_type: tokenType,
|
token_type: tokenType,
|
||||||
} = verifiedCredentials;
|
} = verifiedCredentials;
|
||||||
|
|
||||||
const { data: user }: any = await this.httpClient.get('/me', {
|
const { data: user }: any = await this.client.get('/me', {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${accessToken}`,
|
Authorization: `Bearer ${accessToken}`,
|
||||||
},
|
},
|
||||||
@@ -82,7 +82,7 @@ export default class Authentication {
|
|||||||
|
|
||||||
async isStillVerified() {
|
async isStillVerified() {
|
||||||
try {
|
try {
|
||||||
await this.httpClient.get('/me', {
|
await this.client.get('/me', {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${this.connectionData.accessToken}`,
|
Authorization: `Bearer ${this.connectionData.accessToken}`,
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user