Skip to content

Commit

Permalink
feat(bluesky): add bluesky integration
Browse files Browse the repository at this point in the history
  • Loading branch information
ridvanakca committed May 27, 2024
1 parent 5b7b8c9 commit 05f42bd
Show file tree
Hide file tree
Showing 11 changed files with 156 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/backend/src/apps/bluesky/assets/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions packages/backend/src/apps/bluesky/auth/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import verifyCredentials from './verify-credentials.js';
import isStillVerified from './is-still-verified.js';
import refreshToken from './refresh-token.js';

export default {
fields: [
{
key: 'handle',
label: 'Your Bluesky Handle',
type: 'string',
required: true,
readOnly: false,
value: null,
placeholder: null,
description: '',
clickToCopy: false,
},
{
key: 'password',
label: 'Your Bluesky Password',
type: 'string',
required: true,
readOnly: false,
value: null,
placeholder: null,
description: '',
clickToCopy: false,
},
],

verifyCredentials,
isStillVerified,
refreshToken,
};
8 changes: 8 additions & 0 deletions packages/backend/src/apps/bluesky/auth/is-still-verified.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import getCurrentUser from '../common/get-current-user.js';

const isStillVerified = async ($) => {
const currentUser = await getCurrentUser($);
return !!currentUser.did;
};

export default isStillVerified;
24 changes: 24 additions & 0 deletions packages/backend/src/apps/bluesky/auth/refresh-token.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const refreshToken = async ($) => {
const { refreshJwt } = $.auth.data;

const { data } = await $.http.post(
'/com.atproto.server.refreshSession',
null,
{
headers: {
Authorization: `Bearer ${refreshJwt}`,
},
additionalProperties: {
skipAddingAuthHeader: true,
},
}
);

await $.auth.set({
accessJwt: data.accessJwt,
refreshJwt: data.refreshJwt,
did: data.did,
});
};

export default refreshToken;
23 changes: 23 additions & 0 deletions packages/backend/src/apps/bluesky/auth/verify-credentials.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const verifyCredentials = async ($) => {
const handle = $.auth.data.handle;
const password = $.auth.data.password;

const body = {
identifier: handle,
password,
};

const { data } = await $.http.post('/com.atproto.server.createSession', body);

await $.auth.set({
accessJwt: data.accessJwt,
refreshJwt: data.refreshJwt,
});

await $.auth.set({
did: data.did,
screenName: data.handle,
});
};

export default verifyCredentials;
12 changes: 12 additions & 0 deletions packages/backend/src/apps/bluesky/common/add-auth-header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const addAuthHeader = ($, requestConfig) => {
if (requestConfig.additionalProperties?.skipAddingAuthHeader)
return requestConfig;

if ($.auth.data?.accessJwt) {
requestConfig.headers.Authorization = `Bearer ${$.auth.data.accessJwt}`;
}

return requestConfig;
};

export default addAuthHeader;
15 changes: 15 additions & 0 deletions packages/backend/src/apps/bluesky/common/get-current-user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const getCurrentUser = async ($) => {
const handle = $.auth.data.handle;

const params = {
actor: handle,
};

const { data: currentUser } = await $.http.get('/app.bsky.actor.getProfile', {
params,
});

return currentUser;
};

export default getCurrentUser;
16 changes: 16 additions & 0 deletions packages/backend/src/apps/bluesky/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import defineApp from '../../helpers/define-app.js';
import addAuthHeader from './common/add-auth-header.js';
import auth from './auth/index.js';

export default defineApp({
name: 'Bluesky',
key: 'bluesky',
iconUrl: '{BASE_URL}/apps/bluesky/assets/favicon.svg',
authDocUrl: '{DOCS_URL}/apps/bluesky/connection',
supportsConnections: true,
baseUrl: 'https://bluesky.app',
apiBaseUrl: 'https://bsky.social/xrpc',
primaryColor: '1185fd',
beforeRequest: [addAuthHeader],
auth,
});
6 changes: 6 additions & 0 deletions packages/docs/pages/.vitepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ export default defineConfig({
{ text: 'Connection', link: '/apps/appwrite/connection' },
],
},
{
text: 'Bluesky',
collapsible: true,
collapsed: true,
items: [{ text: 'Connection', link: '/apps/bluesky/connection' }],
},
{
text: 'Carbone',
collapsible: true,
Expand Down
10 changes: 10 additions & 0 deletions packages/docs/pages/apps/bluesky/connection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Bluesky

:::info
This page explains the steps you need to follow to set up the Bluesky connection in Automatisch. If any of the steps are outdated, please let us know!
:::

1. Enter your `Bluesky Handle` from the page to the `Your Bluesky Handle` field on Automatisch.
1. Enter your `Bluesky Password` from the page to the `Your Bluesky Password` field on Automatisch.
1. Click **Submit** button on Automatisch.
1. Congrats! Start using your new Bluesky connection within the flows.
4 changes: 4 additions & 0 deletions packages/docs/pages/public/favicons/bluesky.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 05f42bd

Please sign in to comment.