Skip to content
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion server/api/atproto/bluesky-author-profiles.get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { AuthorSchema } from '#shared/schemas/blog'
import { Client } from '@atproto/lex'
import type { Author, ResolvedAuthor } from '#shared/schemas/blog'
import * as app from '#shared/types/lexicons/app'
import * as crypto from 'node:crypto'

export default defineCachedEventHandler(
async event => {
Expand Down Expand Up @@ -75,7 +76,11 @@ export default defineCachedEventHandler(
maxAge: CACHE_MAX_AGE_ONE_DAY,
getKey: event => {
const { authors } = getQuery(event)
return `author-profiles:${authors ?? 'npmx.dev'}`
if (!authors) {
return 'author-profiles:npmx.dev'
}
const key = crypto.createHash('sha256').update(JSON.stringify(authors)).digest('hex')
return `author-profiles:${key}`
},
},
)
1 change: 0 additions & 1 deletion server/routes/.well-known/jwks.json.get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { loadJWKs } from '#server/utils/atproto/oauth'
export default defineEventHandler(async _ => {
const keys = await loadJWKs()
if (!keys) {
console.error('Failed to load JWKs. May not be set')
return []
}

Expand Down
18 changes: 15 additions & 3 deletions server/utils/atproto/oauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,25 @@ export async function loadJWKs(): Promise<Keyset | undefined> {
// If we ever need to add multiple JWKs to rotate keys we will need to add a new one
// under a new variable and update here
const jwkOne = useRuntimeConfig().oauthJwkOne
if (!jwkOne) return undefined
if (!jwkOne) {
if (import.meta.test) {
// eslint-disable-next-line no-console
console.error('Failed to load JWKs (not set).')
}
return undefined
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

// For multiple keys if we need to rotate
// const keys = await Promise.all([JoseKey.fromImportable(jwkOne)])

const keys = await JoseKey.fromImportable(jwkOne)
return new Keyset([keys])
try {
const keys = await JoseKey.fromImportable(jwkOne)
return new Keyset([keys])
} catch (e) {
// eslint-disable-next-line no-console
console.error('Failed to load JWKs.', e)
return undefined
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
}

async function getOAuthSession(event: H3Event): Promise<{
Expand Down
Loading