Authorization Code
- Code를 전달하고 Token을 받는 방식
- Refresh Token의 사용이 가능함
- 간편 로그인 기능에서 많이 사용되는 방식
USE
Client 수정하기
- AuthorizationServerConfig.java
@Bean
public RegisteredClientRepository registeredClientRepository() {
RegisteredClient oidcClient = RegisteredClient.withId(UUID.randomUUID().toString())
.clientId("my-client")
.clientSecret("{noop}mypassword")
.clientAuthenticationMethod(ClientAuthenticationMethod.CLIENT_SECRET_POST)
.authorizationGrantType(AuthorizationGrantType.AUTHORIZATION_CODE)
.authorizationGrantType(AuthorizationGrantType.REFRESH_TOKEN)
.redirectUri("http://localhost:8080")
.postLogoutRedirectUri("http://localhost:8080/")
.scope(OidcScopes.OPENID)
.clientSettings(ClientSettings.builder().requireAuthorizationConsent(true).build())
.tokenSettings(TokenSettings.builder().accessTokenTimeToLive(Duration.ofSeconds(360)).build())
.build();
return new InMemoryRegisteredClientRepository(oidcClient);
}
- Authorization code 방식의 경우 redirectUri이 필요하다.
Code 받기

- 다음의 생성된 URL에 접속하여 로그인을 진행하면 URL에 Code가 생성된다.
Token 받기

- 다음과 같이 요청을 통해 토큰을 받을 수 있다.