import { Hono } from 'hono' const app = new Hono() // define config const OAUTH_CONFIG = { authServerUrl: 'http://localhost:3020', clientId: process.env.CLIENT_ID, // 클라이언트 등록 후 설정 필요 clientSecret: process.env.CLIENT_SECRET, // 필요한 경우 redirectUri: process.env.REDIRECT_URI, scope: 'profile' } app.get('/', (c) => { return c.html(`

Attacker

Profile

`) }) app.get("/profile", async (c) => { const accessToken = c.req.query('access_token') try { // 바로 프로필 조회 const profileResponse = await fetch(`${OAUTH_CONFIG.authServerUrl}/api/me`, { headers: { 'Authorization': `Bearer ${accessToken}` } }) if (!profileResponse.ok) { return c.html(`

프로필 조회 실패

토큰은 발급되었지만 프로필 조회에 실패했습니다.

상태 코드: ${profileResponse.status}

홈으로 `) } const profile = await profileResponse.json() as any // 토큰 정보와 프로필을 함께 표시 return c.html(` 인증 완료 - 프로필

👤 사용자 프로필

사용자 ID: ${profile.id || 'N/A'}
사용자명: ${profile.username || 'N/A'}
${JSON.stringify(profile, null, 2)}
홈으로
`) } catch (error: any) { return c.html(`

오류 발생

토큰 교환 또는 프로필 조회 중 오류가 발생했습니다: ${error?.message || '알 수 없는 오류'}

홈으로 `) } }) export default { port: 5002, fetch: app.fetch, }