Spring OAuth2.0
OAuth์ ๊ธฐ๋ณธ ์ค๋ช ์ ์ฌ๊ธฐ๋ฅผ ์ฐธ๊ณ ํ์
Spring์์ OAuth๋ฅผ ์ ์ฉ
Password Grant Type?
๊ณ์ ์ ๋ณด๋ฅผ ๊ฐ์ง๊ณ ์๋ ์ฑ์์ ์ฌ์ฉํ ์ ์๋ ๋ฐฉ์์ผ๋ก ๋น๋ฐ๋ฒํธ,์์ด๋,grant type์ request์ ํ๋ผ๋ฏธํฐ๋ก, client_id์ client_Secret์ header์ ๋ฃ์ด ์ค ์ ์๋ค.
ํจ์ค์๋๋ฅผ ์ง์ ์๊ตฌํ๊ธฐ ๋๋ฌธ์ ์๋ํํฐํํ ๋๊ฒจ์ฃผ๋ ๊ฒ์ด ์๋ ๊ณ์ ์ ๋ณด๋ฅผ ๊ฐ์ง๊ณ ์๋ ๊ทธ ์ฑ์์๋ง ์ฌ์ฉ๊ฐ๋ฅํ ๋ฐฉ์. (์๋น์ค ์ค๋๊ฐ ๋ง๋ ํด๋ผ์ด์ธํธ์์ ์ฌ์ฉํ๋ Grant Type)
1ํ๋ง์ Access Token์ ๋ฐ์์ฌ ์ ์๋ค.
https://developer.okta.com/blog/2018/06/29/what-is-the-oauth2-password-grant
AuthorizationServer ์ค์ (์ธ์ฆ ์๋ฒ)
@EnableAuthorizationServer ๊ณผ extends AuthorizationServerConfigurerAdapter์ ์ด์ฉํด configure ์ธ๊ฐ ๋งค์๋ override
configure(AuthorizationServerSecurityConfigurer security)
passwordEncode ์ค์
configure(ClientDetailsServiceConfigurer clients)
ํ ํฐ ์ ์ฅ๋ฐฉ์
ํด๋ผ์ด์ธํธ ์ค์ (clinet id)
grantType
scopes
secret
acccessToken์๊ฐ
refreshToken์๊ฐ
configure(AuthorizationServerEndpointsConfigurer
tokenSore
authenticationManager
userDatailSErvice
httpBasic๋ฉ์๋๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํด dependency ์ถ๊ฐ
ResourceServer ์ค์
@EnableResourceServer ๊ณผ extends ResourceServerConfigurerAdapter์ ์ด์ฉํด configure ๋๊ฐ ๋งค์๋ override
configure(ResourceServerSecurityConfigurer resources)
๋ฆฌ์์ค ID
configure(HttpSecurity http)
์ ๊ทผ ๊ถํ (annoymous, authenticated)
๋ฉ์๋์ url์ ๋ํ ์ ๊ทผ ๊ถํ
ex.
GET /api/** : permit all
POST /api/** : authenticated
PUT /api/** : authenticated
์๋ฌ ์ฒ๋ฆฌ
accessDeniedHandler(OAuth2AccessDeniedHandler())
Last updated