Skip to content

Commit

Permalink
use dynamic metadata and remove old api endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
anbraten committed Nov 28, 2024
1 parent 76af988 commit 4d97151
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 65 deletions.
5 changes: 2 additions & 3 deletions composables/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { withoutProtocol } from 'ufo'
import type { PushNotificationPolicy, PushNotificationRequest } from '~/composables/push-notifications/types'
import {
DEFAULT_POST_CHARS_LIMIT,
OAUTH_SCOPE,
STORAGE_KEY_CURRENT_USER_HANDLE,
STORAGE_KEY_NODES,
STORAGE_KEY_NOTIFICATION,
Expand Down Expand Up @@ -364,16 +365,14 @@ export function clearUserLocalStorage(account?: ProfileViewDetailed) {
})
}

const OAUTH_SCOPE = 'atproto transition:generic transition:chat.bsky'

function isLoopbackHost(host: string) {
return host === 'localhost' || host === '127.0.0.1' || host === '[::1]'
}

async function loadOAuthClient(): Promise<BrowserOAuthClient> {
const isLocalDev = typeof window !== 'undefined' && isLoopbackHost(window.location.hostname)

let clientId = `${window.location.protocol}//${window.location.host}/oauth/client-metadata.json`
let clientId = `${window.location.protocol}//${window.location.host}/api/oauth/client-metadata.json`

if (isLocalDev) {
const redirectUri = encodeURIComponent(
Expand Down
2 changes: 2 additions & 0 deletions constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ export const THEME_COLORS = {
backgroundDark: '#fafafa',
backgroundLight: '#111111',
} as const

export const OAUTH_SCOPE = 'atproto transition:generic transition:chat.bsky'
12 changes: 0 additions & 12 deletions public/oauth/client-metadata.json

This file was deleted.

3 changes: 0 additions & 3 deletions server/api/[server]/login.ts

This file was deleted.

47 changes: 0 additions & 47 deletions server/api/[server]/oauth/[origin].ts

This file was deleted.

34 changes: 34 additions & 0 deletions server/api/oauth/client-metadata.json.get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { OAUTH_SCOPE } from '~/constants'

export default defineEventHandler(async (event) => {
const requestUrl = getRequestURL(event)

const proto = getHeader(event, 'x-forwarded-proto')
const host = getHeader(event, 'x-forwarded-host')
if (proto && host) {
const { protocol, hostname, port } = new URL(`${proto}://${host}`)
requestUrl.protocol = protocol
requestUrl.hostname = hostname
requestUrl.port = port
}

return {
client_id: requestUrl.href,
client_uri: new URL('/', requestUrl).href,
redirect_uris: [new URL('/', requestUrl).href],
response_types: ['code'],
grant_types: ['authorization_code'],
token_endpoint_auth_method: 'none',
scope: OAUTH_SCOPE,
dpop_bound_access_tokens: true,
application_type: 'web',
client_name: 'Nimbus',
logo_uri: new URL(
'/pwa-192x192.png',
requestUrl,
).href,
// tos_uri: 'https://example.com/tos',
// policy_uri: 'https://example.com/policy',
// jwks_uri: 'https://example.com/jwks',
}
})

0 comments on commit 4d97151

Please sign in to comment.