Backend2024년 11월 1일2분 읽기

OAuth 2.0 완벽 이해 — Authorization Code Flow 실전 구현

YS
YoungSam
조회 244

Authorization Code Flow

가장 안전한 OAuth 2.0 흐름입니다. 서버 사이드 애플리케이션에 권장됩니다.

흐름

  1. 사용자를 인증 서버로 리다이렉트
  2. 인증 후 code를 콜백 URL로 전달
  3. 서버에서 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();
});
OAuthAuthenticationSecurity

댓글 0

아직 댓글이 없습니다.