refactor: Pass app data within the constructor of an app

This commit is contained in:
Faruk AYDIN
2022-02-27 18:22:17 +03:00
committed by Ali BARIN
parent 003213d223
commit c864a1062d
24 changed files with 216 additions and 174 deletions

View File

@@ -1,15 +1,17 @@
import FlickrApi from 'flickr-sdk';
import App from '../../models/app';
import Field from '../../types/field';
export default class Authentication {
oauthClient: any
client: any
connectionData: any
appData: any
oauthClient: any;
client: any;
connectionData: any;
appData: any;
constructor(connectionData: any) {
this.oauthClient = new FlickrApi.OAuth(connectionData.consumerKey, connectionData.consumerSecret);
constructor(appData: any, connectionData: any) {
this.oauthClient = new FlickrApi.OAuth(
connectionData.consumerKey,
connectionData.consumerSecret
);
if (connectionData.accessToken && connectionData.accessSecret) {
this.client = new FlickrApi(
@@ -17,21 +19,26 @@ export default class Authentication {
connectionData.consumerKey,
connectionData.consumerSecret,
connectionData.accessToken,
connectionData.accessSecret,
connectionData.accessSecret
)
);
}
this.connectionData = connectionData;
this.appData = App.findOneByKey('flickr');
this.appData = appData;
}
async createAuthData() {
const appFields = this.appData.fields.find((field: Field) => field.key == 'oAuthRedirectUrl')
const appFields = this.appData.fields.find(
(field: Field) => field.key == 'oAuthRedirectUrl'
);
const callbackUrl = appFields.value;
const oauthData = (await this.oauthClient.request(callbackUrl)).body;
const url = await this.oauthClient.authorizeUrl(oauthData.oauth_token, 'delete');
const url = await this.oauthClient.authorizeUrl(
oauthData.oauth_token,
'delete'
);
return {
accessToken: oauthData.oauth_token,
@@ -41,11 +48,13 @@ export default class Authentication {
}
async verifyCredentials() {
const verifiedCredentials = (await this.oauthClient.verify(
this.connectionData.accessToken,
this.connectionData.oauthVerifier,
this.connectionData.accessSecret
)).body;
const verifiedCredentials = (
await this.oauthClient.verify(
this.connectionData.accessToken,
this.connectionData.oauthVerifier,
this.connectionData.accessSecret
)
).body;
return {
consumerKey: this.connectionData.consumerKey,
@@ -53,8 +62,8 @@ export default class Authentication {
accessToken: verifiedCredentials.oauth_token,
accessSecret: verifiedCredentials.oauth_token_secret,
userId: verifiedCredentials.user_nsid,
screenName: verifiedCredentials.fullname
}
screenName: verifiedCredentials.fullname,
};
}
async isStillVerified() {

View File

@@ -1,9 +1,9 @@
import Authentication from './authentication'
import Authentication from './authentication';
export default class Flickr {
authenticationClient: any
authenticationClient: any;
constructor(connectionData: any) {
this.authenticationClient = new Authentication(connectionData);
constructor(appData: any, connectionData: any) {
this.authenticationClient = new Authentication(appData, connectionData);
}
}