feat: add Flickr as a connection
This commit is contained in:
1
packages/backend/src/apps/flickr/index.d.ts
vendored
Normal file
1
packages/backend/src/apps/flickr/index.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
declare module 'flickr-sdk';
|
46
packages/backend/src/apps/flickr/index.ts
Normal file
46
packages/backend/src/apps/flickr/index.ts
Normal file
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
115
packages/backend/src/apps/flickr/info.json
Normal file
115
packages/backend/src/apps/flickr/info.json
Normal file
@@ -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}"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
Reference in New Issue
Block a user