루트 엔드포인트에서 OAuth 인증 URL 생성 로직 추가 및 콜백 경로 수정

This commit is contained in:
암냥 2025-07-05 13:57:00 +09:00
commit 5dbc8345ba

View file

@ -6,6 +6,20 @@ const fetch = require("node-fetch");
app.use(express.static("public")); // public 폴더 내 정적 파일 제공
app.use(express.json()); // JSON 본문 파싱
app.get("/", (req, res) => {
const clientId = "16435018183-9a880bertda0en85387ge8f8mgsves71.apps.googleusercontent.com"; // 반드시 수정
const redirectUri = "https://google-oauth-access-token-whs.hako.li/callback";
const authUrl = "https://accounts.google.com/o/oauth2/v2/auth?" +
`client_id=${clientId}` +
`&redirect_uri=${redirectUri}` +
`&response_type=token` + // code로 변경하여 리프레시 토큰도 받을 수 있도록
`&scope=email%20profile
`; // 매번 동의 화면을 표시하여 리프레시 토큰 확보
res.redirect(authUrl);
});
// Access Token 수신용 엔드포인트
app.post("/token", async (req, res) => {
const token = req.body.access_token;
@ -28,7 +42,7 @@ app.post("/token", async (req, res) => {
});
app.get("/callback", (req, res) => {
res.sendFile(path.join(__dirname, "callback/callback.html"));
res.sendFile(path.join(__dirname, "callback.html"));
});
const PORT = 39090;