refactor: Pass app data within the constructor of an app
This commit is contained in:
@@ -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() {
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user