Skip to content

Commit

Permalink
Fix for OAuth localhost scopes (#16)
Browse files Browse the repository at this point in the history
* fix oauth localhost usage

* misc fixes to profile validation and status view
  • Loading branch information
devinivy authored Oct 5, 2024
1 parent 9cd25e3 commit 7077651
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 106 deletions.
118 changes: 20 additions & 98 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
"@atproto/common": "^0.4.1",
"@atproto/api": "^0.13.4",
"@atproto/identity": "^0.4.0",
"@atproto/lexicon": "0.4.1-rc.0",
"@atproto/lexicon": "^0.4.2",
"@atproto/oauth-client-node": "^0.1.0",
"@atproto/repo": "0.4.2-rc.0",
"@atproto/sync": "^0.1.0",
"@atproto/syntax": "^0.3.0",
"@atproto/xrpc-server": "^0.6.3",
Expand Down
3 changes: 2 additions & 1 deletion src/auth/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import { SessionStore, StateStore } from './storage'
export const createClient = async (db: Database) => {
const publicUrl = env.PUBLIC_URL
const url = publicUrl || `http://127.0.0.1:${env.PORT}`
const enc = encodeURIComponent
return new NodeOAuthClient({
clientMetadata: {
client_name: 'AT Protocol Express App',
client_id: publicUrl
? `${url}/client-metadata.json`
: `http://localhost?redirect_uri=${encodeURIComponent(`${url}/oauth/callback`)}`,
: `http://localhost?redirect_uri=${enc(`${url}/oauth/callback`)}&scope=${enc('atproto transition:generic')}`,
client_uri: url,
redirect_uris: [`${url}/oauth/callback`],
scope: 'atproto transition:generic',
Expand Down
7 changes: 4 additions & 3 deletions src/ingester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export function createIngester(db: Database, idResolver: IdResolver) {
handleEvent: async (evt) => {
// Watch for write events
if (evt.event === 'create' || evt.event === 'update') {
const now = new Date()
const record = evt.record

// If the write is a valid status update
Expand All @@ -27,12 +28,12 @@ export function createIngester(db: Database, idResolver: IdResolver) {
authorDid: evt.did,
status: record.status,
createdAt: record.createdAt,
indexedAt: new Date().toISOString(),
indexedAt: now.toISOString(),
})
.onConflict((oc) =>
oc.column('uri').doUpdateSet({
status: record.status,
indexedAt: new Date().toISOString(),
indexedAt: now.toISOString(),
})
)
.execute()
Expand All @@ -42,7 +43,7 @@ export function createIngester(db: Database, idResolver: IdResolver) {
evt.collection === 'xyz.statusphere.status'
) {
// Remove the status from our SQLite
await db.deleteFrom('status').where({ uri: evt.uri.toString() })
await db.deleteFrom('status').where('uri', '=', evt.uri.toString()).execute()
}
},
onError: (err) => {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ function toBskyLink(did: string) {
}

function ts(status: Status) {
const createdAt = new Date(status.createdAt)
const indexedAt = new Date(status.indexedAt)
const updatedAt = new Date(status.updatedAt)
if (updatedAt > indexedAt) return updatedAt.toDateString()
if (createdAt < indexedAt) return createdAt.toDateString()
return indexedAt.toDateString()
}

0 comments on commit 7077651

Please sign in to comment.