Authorization Code Flow
가장 안전한 OAuth 2.0 흐름입니다. 서버 사이드 애플리케이션에 권장됩니다.
흐름
- 사용자를 인증 서버로 리다이렉트
- 인증 후 code를 콜백 URL로 전달
- 서버에서 code를 token으로 교환
// 콜백 처리
app.get("/callback", async (req, res) => {
const { code } = req.query;
const tokenRes = await fetch("https://auth.example.com/token", {
method: "POST",
body: new URLSearchParams({
grant_type: "authorization_code",
code, redirect_uri: CALLBACK_URL,
client_id: CLIENT_ID, client_secret: CLIENT_SECRET,
}),
});
const { access_token } = await tokenRes.json();
});
댓글 0