-
Notifications
You must be signed in to change notification settings - Fork 313
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bluesky): add bluesky integration
- Loading branch information
1 parent
5b7b8c9
commit 05f42bd
Showing
11 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
23
packages/backend/src/apps/bluesky/auth/verify-credentials.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
12
packages/backend/src/apps/bluesky/common/add-auth-header.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
15
packages/backend/src/apps/bluesky/common/get-current-user.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.