์คํ๋ง ๋ถํธ, ์คํ๋ง ์ํ๋ฆฌํฐ, OAuth2๋ฅผ ๊ธฐ๋ฐ์ผ๋ก JWT ๋ก๊ทธ์ธ์ ๊ตฌํํ ์์ ์ ๋๋ค. ๊ตฌ๊ธ๊ณผ ๋ค์ด๋ฒ ๋ก๊ทธ์ธ ๊ธฐ๋ฅ๋ง์ด ๊ตฌํ๋์ด ์์ต๋๋ค. JWT ์ ํจ์๊ฐ์ 300์ด๋ก ์ค์ ๋์๊ณ ์๋ ์ฌ๋ก๊ทธ์ธ์ด๋ ๊ถํ ๋ถ๋ถ์ ๊ตฌํ๋์ด ์์ง ์์ต๋๋ค.
OAuth2์ ์ธ์ฆ ๊ฒฐ๊ณผ๋ฅผ ์ธ์ ์ ์ ์ฅํ๋ ๋์ JWT ํ ํฐ์ ์์ฑํ๊ณ ์ฟ ํค๋ฅผ ํตํด ์ฌ์ฉ์ ์์ด์ ํธ(์น ๋ธ๋ผ์ฐ์ )์ ์ ์กํฉ๋๋ค. JWT๋ฅผ ์ฟ ํค์ ์ ์ฅํ๊ฒ ๋๋ฉด ์น ๋ธ๋ผ์ฐ์ ์ ๋ชจ๋ ์์ฒญ์ ํฌํจ๋์ด API ์๋ฒ์ ์ ๋ฌ๋๊ณ ์๋ฒ๋ JWT๋ฅผ ํ์ธํ์ฌ ํด๋น ์ฌ์ฉ์์ ์์ฒญ์ ์ฒ๋ฆฌํ ์ ์์ต๋๋ค.
-
๋ ํฌ์งํ ๋ฆฌ์์ ์์คํ์ผ ๋ฐ๊ธฐ
๊นํ๋ธ ๋ ํฌ์งํ ๋ฆฌ์์ ์์คํ์ผ์ ๋ฐ์ต๋๋ค. ๋ฐฑ์๋๋ ์คํ๋ง ๋ถํธ, ํ๋ก ํธ์๋๋ react.js๋ก ์์ฑ๋์ด ์์ต๋๋ค. ํ๋ก ํธ์๋ ํ๋ก์ ํธ๋ ์ฌ๊ธฐ๋ฅผ ์ฐธ๊ณ ํ์ญ์์ค.#back-end git clone https://github.com/boyd-dev/SimpleSpringBoot.git #front-end git clone https://github.com/boyd-dev/SimpleReactApp.git -
ํ๋ก์ ํธ๋ช ๋ณ๊ฒฝํ๊ธฐ
์ดํด๋ฆฝ์ค(๋๋ STS)์์ ํ๋ก์ ํธ๋ฅผ ์ด๊ธฐ ์ ์ ์ค๋ณต๋๋ ํ๋ก์ ํธ๋ช ์ด ์๋์ง ํ์ธํฉ๋๋ค. ํ๋ก์ ํธ๋ช ์demo-jwt์ ๋๋ค. ์ด๋ฏธ ๋์ผํ ์ด๋ฆ์ ํ๋ก์ ํธ๊ฐ ์๋ ๊ฒฝ์ฐsettings.gradle์ ์ด์ด์ ์ด๋ฆ์ ๋ณ๊ฒฝํฉ๋๋ค.rootProject.name = 'demo-jwt' -
์ดํด๋ฆฝ์ค์์ ํ๋ก์ ํธ import ํ๊ธฐ
์ดํด๋ฆฝ์ค ๋ฉ๋ด File>Import>Gradle>Existing Gradle Porject๋ฅผ ์คํํฉ๋๋ค. Project root directory๋ฅผ git clone์ผ๋ก ๊ฐ์ ธ์จ ์คํ๋ง ๋ถํธ ํ๋ก์ ํธ ๋๋ ํ ๋ฆฌ๋ก ์ง์ ํฉ๋๋ค. ๊ฐ์ ธ์ค๊ธฐ๊ฐ ์๋ฃ๋๋ฉด ์ดํด๋ฆฝ์ค์ ํ๋ก์ ํธ ํ์๊ธฐ์์demo-jwt๋ฅผ ํ์ธํฉ๋๋ค. -
์ค์ ํ์ผ ๋ณ๊ฒฝํ๊ธฐ(๋ก์ปฌํ๊ฒฝ ๊ธฐ์ค)
application.ymlํ์ผ์ ์ด์ด์ ์ค์ ์ ๋ณ๊ฒฝํฉ๋๋ค.#Local๋ถ๋ถ์ ์๋client-id์client-secret์ ์ธ์ฆ ๊ณต๊ธ์์ธ ๊ตฌ๊ธ๊ณผ ๋ค์ด๋ฒ์์ ํ์ธํ์ฌ ์ ๋ ฅํฉ๋๋ค.redirect-uri๋ ๊ตฌ๊ธ๊ณผ ๋ค์ด๋ฒ์์ ์ค์ ํ ์ธ์ฆ์ฑ๊ณต ํ ํธ์ถ๋๋ URL์ ๋๋ค. ๊ฐ ์ธ์ฆ ๊ณต๊ธ์์ ์ค์ ์http://localhost:8080/oauth2/callback/{google or naver}์ผ๋ก ์ค์ ํฉ๋๋ค (๋ค๋ฅธ ๊ฒฝ๋ก๋ก ๋ฐ๊ฟ ์๋ ์์ง๋ง ์ฌ๊ธฐ์๋/oauth2/callback/์ผ๋ก ์ ํฉ๋๋ค).google: client-id: <Your client-id> client-secret: <Your client-secret> scope: profile, email redirect-uri: http://localhost:8080/oauth2/callback/google client-name: google naver: client-id: <Your client-id> client-secret: <Your client-secret> redirect-uri: http://localhost:8080/oauth2/callback/naver authorization-grant-type: authorization_code client-name: naver -
ํ๋ก ํธ ์ ํ๋ฆฌ์ผ์ด์ ํ๋ก์ ํธ ์์น ์ง์ ํ๊ธฐ
build.gradleํ์ผ์ ์ด์ด์ git clone์ผ๋ก ๋ฐ์ ํ๋ก ํธ์๋ ์ ํ๋ฆฌ์ผ์ด์ ์ ํ๋ก์ ํธ ์์น๋ฅผ ์ง์ ํฉ๋๋ค.def frontendDir = "<front-end application project directory>" -
๋น๋ํ๊ธฐ
ํ๋ก์ ํธ ํ์์ฐฝ์์demo-jwt๋ฅผ ์ ํํ๊ณ ๋ง์ฐ์ค ์ค๋ฅธ์ชฝ ํด๋ฆญํ์ฌ Gradle>Refresh Gradle Project๋ฅผ ์คํํ์ฌ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ค์ ๋ฐ์ต๋๋ค.์ดํด๋ฆฝ์ค ๋ฉ๋ด Window>Show View>Gradle>Gradle Tasks๋ฅผ ์คํํฉ๋๋ค. ํธ๋ฆฌ์์
buildํด๋๋ฅผ ์ด์ด์buildํญ๋ชฉ์ ์ ํํ๊ณ ๋ง์ฐ์ค ์ค๋ฅธ์ชฝ ํด๋ฆญํ์ฌRun Gradle Tasks๋ฅผ ์คํํฉ๋๋ค. -
์ ์ ๋ฆฌ์์ค ํ์ธํ๊ธฐ
์คํ๋ง ๋ถํธ ํ๋ก์ ํธ๊ฐ ๋น๋๋๋ฉด์ ํ๋ก ํธ์๋ ์ ํ๋ฆฌ์ผ์ด์ ๋ ํจ๊ป ์์ฑ๋ฉ๋๋ค(ํ๋ก ํธ์๋ ์ ํ๋ฆฌ์ผ์ด์ ์/resources/static/ํ์๋ก ๋ณต์ฌ๋ฉ๋๋ค). ์คํ๋ง ๋ถํธ ์ฑ ์คํ ์ ์/resources/static/๋ฅผ F5๋ก ๋ฆฌํ๋ ์ ํ์ฌ ๋ฆฌ์กํธ ๋น๋๊ฐ ๋ณต์ฌ๋์๋์ง ํ์ธํฉ๋๋ค. -
์คํ๋ง ๋ถํธ ์ ํ๋ฆฌ์ผ์ด์ ์คํ
Boot Dashboard์์ ํด๋น ํ๋ก์ ํธ๋ฅผ ์ ํํ ํ ์คํํฉ๋๋ค. ์น ๋ธ๋ผ์ฐ์ ์์http://localhost:8080์ ์ ์ํ์ฌ ๋์์ ํ์ธํฉ๋๋ค. ๐