Section 6: Users Microservice 2 - KwangtaekJung/MSA-SpringCloud-user-service GitHub Wiki

Section 6: Users Microservice 2

  • Users Microservice - Login
  • JWT (Json Web Token)
  • API Gateway service - AuthorizationHeaderFilter

Users Microservice - Login

  • /login API๋Š” Spring Security์—์„œ ์ œ๊ณตํ•œ๋‹ค. ์ง์ ‘ ๋งŒ๋“ค์ง€ ์•Š๊ณ ๋„ ํ…Œ์ŠคํŠธ ๊ฐ€๋Šฅํ•จ.
  • ๋กœ๊ทธ์ธ ์ฒ˜๋ฆฌ ์ ˆ์ฐจ
    • AuthenticationFilter::attemptAuthentication()
    • UsernamePasswordAuthenticationToken
    • UserDetailService::loaduserByusername() -> UserRepository::findByEmail()
    • AuthenticationFilter::successfulAuthentication()
      • ์ธ์ฆ ์„ฑ๊ณต ์‹œ ์‚ฌ์šฉ์ž์—๊ฒŒ Token ๋ฐœํ–‰
        • Jwts.builder()
        • response.addHeader("token", jwt)

JWT

  • ์ „ํ†ต์ ์ธ ๋ฐฉ๋ฒ•
  • Token ๊ธฐ๋ฐ˜ ๋ฐฉ๋ฒ•
  • JWT ์žฅ์ 
    • ํด๋ผ์ด์–ธํŠธ ๋…๋ฆฝ์ ์ธ ์„œ๋น„์Šค (stateless)
    • CDN (Content Delivery Network)
    • No Cookie-Session (No CSRF, ์‚ฌ์ดํŠธ ๊ฐ„ ์š”์ฒญ ์œ„์กฐ)
    • ์ง€์†์ ์ธ ํ† ํฐ ์ €์žฅ

Bearer Authentication

  • API์— ์ ‘์†ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” access token์„ API ์„œ๋ฒ„์— ์ œ์ถœํ•ด์„œ ์ธ์ฆ ์ฒ˜๋ฆฌ.
  • OAuth๋ฅผ ์œ„ํ•ด์„œ ๊ณ ์•ˆ๋œ ๋ฐฉ๋ฒ•, RFC6750