From 177b5eba48269150f847b35647b2b10d066a896b Mon Sep 17 00:00:00 2001 From: Ali BARIN Date: Sun, 17 Oct 2021 19:29:57 +0200 Subject: [PATCH] feat: add Flickr as a connection --- packages/backend/src/apps/flickr/index.d.ts | 1 + packages/backend/src/apps/flickr/index.ts | 46 ++++++++ packages/backend/src/apps/flickr/info.json | 115 ++++++++++++++++++++ 3 files changed, 162 insertions(+) create mode 100644 packages/backend/src/apps/flickr/index.d.ts create mode 100644 packages/backend/src/apps/flickr/index.ts create mode 100644 packages/backend/src/apps/flickr/info.json diff --git a/packages/backend/src/apps/flickr/index.d.ts b/packages/backend/src/apps/flickr/index.d.ts new file mode 100644 index 00000000..1a21c85c --- /dev/null +++ b/packages/backend/src/apps/flickr/index.d.ts @@ -0,0 +1 @@ +declare module 'flickr-sdk'; diff --git a/packages/backend/src/apps/flickr/index.ts b/packages/backend/src/apps/flickr/index.ts new file mode 100644 index 00000000..ba99e774 --- /dev/null +++ b/packages/backend/src/apps/flickr/index.ts @@ -0,0 +1,46 @@ +import FlickrApi from 'flickr-sdk'; +import App from '../../models/app'; +import Field from '../../types/field'; + +export default class Flickr { + client: any + connectionData: any + appData: any + + constructor(connectionData: any) { + this.client = new FlickrApi.OAuth(connectionData.consumerKey, connectionData.consumerSecret); + + this.connectionData = connectionData; + this.appData = App.findOneByKey('flickr'); + } + + async createAuthLink() { + 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'); + + return { + ...oauthData, + url, + }; + } + + async verifyCredentials() { + const verifiedCredentials = (await this.client.verify( + this.connectionData.accessToken, + this.connectionData.oauthVerifier, + this.connectionData.accessSecret + )).body; + + return { + consumerKey: this.connectionData.consumerKey, + consumerSecret: this.connectionData.consumerSecret, + accessToken: verifiedCredentials.oauth_token, + accessSecret: verifiedCredentials.oauth_token_secret, + userId: verifiedCredentials.user_nsid, + screenName: verifiedCredentials.fullname + } + } +} diff --git a/packages/backend/src/apps/flickr/info.json b/packages/backend/src/apps/flickr/info.json new file mode 100644 index 00000000..84ef5122 --- /dev/null +++ b/packages/backend/src/apps/flickr/info.json @@ -0,0 +1,115 @@ +{ + "name": "Flickr", + "key": "flickr", + "iconUrl": "https://automatisch.io/apps/flickr.png", + "docUrl": "https://automatisch.io/docs/flickr", + "primaryColor": "000000", + "fields": [ + { + "key": "oAuthRedirectUrl", + "label": "OAuth Redirect URL", + "type": "string", + "required": true, + "readOnly": true, + "value": "http://localhost:3001/app/flickr/connections/add", + "placeholder": null, + "description": "When asked to input an OAuth callback or redirect URL in Flickr OAuth, enter the URL above.", + "docUrl": "https://automatisch.io/docs/flickr#oauth-redirect-url", + "clickToCopy": true + }, + { + "key": "consumerKey", + "label": "Consumer Key", + "type": "string", + "required": true, + "readOnly": false, + "value": null, + "placeholder": null, + "description": null, + "docUrl": "https://automatisch.io/docs/flickr#consumer-key", + "clickToCopy": false + }, + { + "key": "consumerSecret", + "label": "Consumer Secret", + "type": "string", + "required": true, + "readOnly": false, + "value": null, + "placeholder": null, + "description": null, + "docUrl": "https://automatisch.io/docs/flickr#consumer-secret", + "clickToCopy": false + } + ], + "authenticationSteps": [ + { + "step": 1, + "type": "mutation", + "name": "createConnection", + "fields": [ + { + "name": "key", + "value": "{key}" + }, + { + "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": "{createConnection.id}" + } + ] + }, + { + "step": 3, + "type": "openWithPopup", + "name": "openAuthPopup", + "fields": [ + { + "name": "url", + "value": "{createAuthLink.url}" + } + ] + }, + { + "step": 4, + "type": "mutation", + "name": "updateConnection", + "fields": [ + { + "name": "id", + "value": "{createConnection.id}" + }, + { + "name": "data", + "value": null, + "fields": [ + { + "name": "oauthVerifier", + "value": "{openAuthPopup.oauth_verifier}" + } + ] + } + ] + } + ] +}