feat: introduce reconnection support for Flickr

This commit is contained in:
Ali BARIN
2021-10-20 21:51:13 +02:00
parent ec4dd8a037
commit 1654abb197
7 changed files with 105 additions and 8 deletions

View File

@@ -3,12 +3,24 @@ import App from '../../models/app';
import Field from '../../types/field';
export default class Flickr {
oauthClient: any
client: any
connectionData: any
appData: any
constructor(connectionData: any) {
this.client = new FlickrApi.OAuth(connectionData.consumerKey, connectionData.consumerSecret);
this.oauthClient = new FlickrApi.OAuth(connectionData.consumerKey, connectionData.consumerSecret);
if (connectionData.accessToken && connectionData.accessSecret) {
this.client = new FlickrApi(
FlickrApi.OAuth.createPlugin(
connectionData.consumerKey,
connectionData.consumerSecret,
connectionData.accessToken,
connectionData.accessSecret,
)
);
}
this.connectionData = connectionData;
this.appData = App.findOneByKey('flickr');
@@ -18,8 +30,8 @@ export default class Flickr {
const appFields = this.appData.fields.find((field: Field) => field.key == 'oAuthRedirectUrl')
const callbackUrl = appFields.value;
const oauthData = (await this.client.request(callbackUrl)).body;
const url = await this.client.authorizeUrl(oauthData.oauth_token, 'delete');
const oauthData = (await this.oauthClient.request(callbackUrl)).body;
const url = await this.oauthClient.authorizeUrl(oauthData.oauth_token, 'delete');
return {
...oauthData,
@@ -28,7 +40,7 @@ export default class Flickr {
}
async verifyCredentials() {
const verifiedCredentials = (await this.client.verify(
const verifiedCredentials = (await this.oauthClient.verify(
this.connectionData.accessToken,
this.connectionData.oauthVerifier,
this.connectionData.accessSecret
@@ -43,4 +55,13 @@ export default class Flickr {
screenName: verifiedCredentials.fullname
}
}
async isStillVerified() {
try {
await this.client.test.login();
return true;
} catch {
return false;
}
}
}

View File

@@ -111,5 +111,75 @@
}
]
}
],
"reconnectionSteps": [
{
"step": 1,
"type": "mutation",
"name": "updateConnection",
"fields": [
{
"name": "id",
"value": "{connection.id}"
},
{
"name": "data",
"value": null,
"fields": [
{
"name": "consumerKey",
"value": "{fields.consumerKey}"
},
{
"name": "consumerSecret",
"value": "{fields.consumerSecret}"
}
]
}
]
},
{
"step": 2,
"type": "mutation",
"name": "createAuthLink",
"fields": [
{
"name": "id",
"value": "{connection.id}"
}
]
},
{
"step": 3,
"type": "openWithPopup",
"name": "openAuthPopup",
"fields": [
{
"name": "url",
"value": "{createAuthLink.url}"
}
]
},
{
"step": 4,
"type": "mutation",
"name": "updateConnection",
"fields": [
{
"name": "id",
"value": "{connection.id}"
},
{
"name": "data",
"value": null,
"fields": [
{
"name": "oauthVerifier",
"value": "{openAuthPopup.oauth_verifier}"
}
]
}
]
}
]
}

View File

@@ -43,7 +43,7 @@ export default class Twitter {
try {
await this.client.currentUser();
return true;
} catch (error) {
} catch {
return false
}
}

View File

@@ -11,7 +11,7 @@
"type": "string",
"required": true,
"readOnly": true,
"value": "http://localhost:3001/app/twitter/connections/add",
"value": "https://localhost:3001/app/twitter/connections/add",
"placeholder": null,
"description": "When asked to input an OAuth callback or redirect URL in Twitter OAuth, enter the URL above.",
"docUrl": "https://automatisch.io/docs/twitter#oauth-redirect-url",