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