π§΅[μ€νλ§ μνλ¦¬ν° OAuth2] OAuth 2.0 Resource Server Fundamentals
1. OAuth 2.0 Resource Server μκ°Permalink
κ°μPermalink
- OAuth 2.0 μΈκ° νλ μμν¬μ μν μ€ ν΄λΌμ΄μΈνΈ λ° μΈκ°μλ²μμ ν΅μ μ λ΄λΉνλ 리μμ€ μλ²μ κΈ°λ₯μ νν° κΈ°λ°μΌλ‘ ꡬνν λͺ¨λ
- κ°λ¨ν μ€μ λ§μΌλ‘ ν΄λΌμ΄μΈνΈμ 리μμ€ μ κ·Ό μ ν, ν ν° κ²μ¦μ μν μΈκ°μλ²μμ ν΅μ λ±μ ꡬνμ΄ κ°λ₯νλ€
- μ΄ν리μΌμ΄μ μ κΆν κ΄λ¦¬λ₯Ό λ³λ μΈκ° μλ²μ μμνλ κ²½μ°μ μ¬μ©ν μ μμΌλ©° 리μμ€ μλ²λ μμ²μ μΈκ°ν λ μ΄ μΈκ° μλ²μ λ¬Όμ΄λ³Ό μ μλ€
OAuth2ResourceServerPermalink
- ν΄λΌμ΄μΈνΈμ μ κ·Όμ μ ννλ μΈκ° μ μ± μ μ€μ νλ€
- μΈκ°μλ²μμ λ°κΈν Access Token μ μ ν¨μ±μ κ²μ¦νκ³ μ κ·Ό λ²μμ λ°λΌ μ μ ν μμμ μ λ¬νλλ‘ μ€μ νλ€
JWTPermalink
- JWT λ‘ μ λ¬λλ ν ν°μ κ²μ¦νκΈ° μν JwtDecoder, BearerTokenAuthenticationFilter, JwtAuthenticationProvider λ±μ ν΄λμ€ λͺ¨λΈλ€μ μ 곡νλ€
- μ체 κ²μ¦ νλ‘μΈμ€λ₯Ό μ§μνλ€
OpaquePermalink
- μΈκ°μλ²μ introspection μλ ν¬μΈνΈλ‘ κ²μ¦ν μ μλ Opaque ν ν°μ μ§μνλ€
- μ€μκ°μΌλ‘ ν ν°μ νμ±ν μ¬λΆλ₯Ό νμΈν μ μλ€
β μμ‘΄μ± μΆκ°Permalink
- 리μμ€ μλ²λ₯Ό μ§μνλ μ½λλ λλΆλΆ spring-security-oauth2-resource-server μ λ€μ΄μλ€. κ·Έλ¬λ JWTλ₯Ό λμ½λ©νκ³ κ²μ¦νλ λ‘μ§μ spring-security-oauth2-jose μ μλ€. λ°λΌμ 리μμ€ μλ²κ° μ¬μ©ν Bearer ν ν°μ JWTλ‘ μΈμ½λ©νλ€λ©΄ λ λͺ¨λμ΄ λͺ¨λ νμνλ€.
dependencies { implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server' testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.security:spring-security-test' }
2. application.yml / OAuth2ResourceServerPropertiesPermalink
νκ²½μ€μ νμΌ κ΅¬μ±Permalink
- application. yml νκ²½μ€μ νμΌμ μλ¬΄λ° μ€μ μ νμ§ μκ³ κΈ°λκ²°κ³Όλ₯Ό νμΈνλ€
- application. yml νκ²½μ€μ νμΌμ OAuth2 ResourceServer κΈ°λ³Έμ€μ ν κΈ°λκ²°κ³Ό νμΈνλ€
OAuth2ResourceServerProperties (prefix = βspring.security.oauth2.resourceserverβ)Permalink
- jwkSetUri μ μΈκ° μλ²μμ μλͺ ν ν ν°μ μμΉλ₯Ό λνλΈλ€
- issuerUri λ μΈκ°μλ²μ μμΉλ₯Ό λνλΈλ€
- publicKeyLocation μ 곡κ°ν€λ₯Ό κ°μ§κ³ μλ νμΌμ μμΉλ₯Ό λνλΈλ€
- jwsAlgorithm μ JWT ν ν°μ μλͺ νκΈ° μν μκ³ λ¦¬μ¦μ λνλΈλ€
- IntrospectionUri λ ν ν°μ κ²μ¦νκΈ° μν introspection μλ ν¬μΈνΈλ₯Ό λνλΈλ€
application. yml μ€μ Permalink
spring:
security:
oauth2:
resourceserver:
jwt:
issuer-uri: http://localhost:8080/realms/oauth2
jwk-set-uri: http://localhost:8080/realms/oauth2/protocol/openid-connect/certs
- issuer-uri = http://localhost:8080λ μΈκ° μλ²κ° λ°κΈν JWT ν ν°μ iss ν΄λ μμ μΆκ°λλ κ°μΌλ‘μ λ°κΈμλ₯Ό λνλΈλ€.
- jwk-set-uri = http://localhost:8080/oauth2/jwksλ μΈκ° μλ²κ° λ°κΈν JWT ν ν°μ 곡κ°ν€ μ 보λ₯Ό κ²μν μ μλ μλν¬μΈνΈλ₯Ό λνλΈλ€.
- 리μμ€ μλ²λ μ체 κ²μ¦ μ€μ μλ μ΄ μμ±μ μ¬μ©νλ©°, μ΄ μμ±μΌλ‘ μΈκ° μλ²μ 곡κ°ν€λ₯Ό μ°Ύκ³ , κ±΄λ΄ λ°μ JWTμ μ ν¨μ±μ κ²μ¬νλ€.
μΈκ° μλ² λ©νλ°μ΄ν° μλν¬μΈνΈPermalink
- issuer-uri νλ‘νΌν°λ₯Ό μ¬μ©νλ €λ©΄ μΈκ° μλ²κ° μ§μνλ μλν¬μΈνΈλ λ°λμ μ
μ€ νλμ¬μΌ νλ€.
- https://localhost:8080/issuer/.well-known/openid-configuration
- https://localhost:8080/.well-known/openid-configuration/issuer
- https://localhost:8080/.well-known/oauth-authorization-server/issuer
- μ΄ μλν¬μΈνΈλ Provider μ€μ μλν¬μΈνΈ λλ μΈκ° μλ² λ©νλ°μ΄ν° μλν¬μΈνΈλΌκ³ νλ€.
ResourceServer#Jwt application.yml μ€μ νλͺ©Permalink
spring:
security:
oauth2:
resourceserver:
jwt:
issuer-uri: http://localhost:8080/realms/oauth2 # μλΉμ€ 곡κΈμ μμΉ
jwk-set-uri: http://localhost:8080/realms/oauth2/protocol/openid-connect/certs # OAuth 2.0 JwkSetUri μλ ν¬μΈνΈ
jws-algorithms: RSA256 # OAuth 2.0 JWS μλͺ
μκ³ λ¦¬μ¦
audiences: http://localhost:8081 # μμ μ μμΉ
public-key-location: classpath:certs/publicKey.txt # OAuth 2.0 JWS κ²μ¦μ μν PublicKey νμΌ μμΉ
- μ μμ± μ€μ issuer-uri νΉμ jwk-set-uri ν κ°λ λ°λμ νμνκ³ λλ¨Έμ§ μμ±μ νμμ μ€μ νλ©΄ λλ€
λκΈλ¨κΈ°κΈ°