|
21 | 21 | import org.junit.jupiter.api.Test;
|
22 | 22 | import org.junit.jupiter.api.extension.ExtendWith;
|
23 | 23 | import sample.AuthorizationCodeGrantFlow;
|
24 |
| -import sample.DeviceAuthorizationGrantFlow; |
25 | 24 | import sample.test.SpringTestContext;
|
26 | 25 | import sample.test.SpringTestContextExtension;
|
27 | 26 |
|
|
32 | 31 | import org.springframework.context.annotation.Import;
|
33 | 32 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
34 | 33 | import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames;
|
| 34 | +import org.springframework.security.oauth2.core.oidc.OidcScopes; |
35 | 35 | import org.springframework.security.oauth2.core.oidc.endpoint.OidcParameterNames;
|
36 | 36 | import org.springframework.security.oauth2.server.authorization.InMemoryOAuth2AuthorizationConsentService;
|
37 | 37 | import org.springframework.security.oauth2.server.authorization.InMemoryOAuth2AuthorizationService;
|
@@ -77,13 +77,13 @@ public void oidcLoginWhenGettingStartedConfigUsedThenSuccess() throws Exception
|
77 | 77 | assertThat(this.authorizationService).isInstanceOf(InMemoryOAuth2AuthorizationService.class);
|
78 | 78 | assertThat(this.authorizationConsentService).isInstanceOf(InMemoryOAuth2AuthorizationConsentService.class);
|
79 | 79 |
|
80 |
| - RegisteredClient registeredClient = this.registeredClientRepository.findByClientId("messaging-client"); |
| 80 | + RegisteredClient registeredClient = this.registeredClientRepository.findByClientId("oidc-client"); |
81 | 81 | assertThat(registeredClient).isNotNull();
|
82 | 82 |
|
83 | 83 | AuthorizationCodeGrantFlow authorizationCodeGrantFlow = new AuthorizationCodeGrantFlow(this.mockMvc);
|
84 | 84 | authorizationCodeGrantFlow.setUsername("user");
|
85 |
| - authorizationCodeGrantFlow.addScope("message.read"); |
86 |
| - authorizationCodeGrantFlow.addScope("message.write"); |
| 85 | + authorizationCodeGrantFlow.addScope(OidcScopes.OPENID); |
| 86 | + authorizationCodeGrantFlow.addScope(OidcScopes.PROFILE); |
87 | 87 |
|
88 | 88 | String state = authorizationCodeGrantFlow.authorize(registeredClient);
|
89 | 89 | assertThatAuthorization(state, OAuth2ParameterNames.STATE).isNotNull();
|
@@ -117,53 +117,6 @@ public void oidcLoginWhenGettingStartedConfigUsedThenSuccess() throws Exception
|
117 | 117 | StringUtils.delimitedListToStringArray(scopes, " "));
|
118 | 118 | }
|
119 | 119 |
|
120 |
| - @Test |
121 |
| - public void deviceAuthorizationWhenGettingStartedConfigUsedThenSuccess() throws Exception { |
122 |
| - this.spring.register(AuthorizationServerConfig.class).autowire(); |
123 |
| - assertThat(this.registeredClientRepository).isInstanceOf(InMemoryRegisteredClientRepository.class); |
124 |
| - assertThat(this.authorizationService).isInstanceOf(InMemoryOAuth2AuthorizationService.class); |
125 |
| - assertThat(this.authorizationConsentService).isInstanceOf(InMemoryOAuth2AuthorizationConsentService.class); |
126 |
| - |
127 |
| - RegisteredClient registeredClient = this.registeredClientRepository.findByClientId("messaging-client"); |
128 |
| - assertThat(registeredClient).isNotNull(); |
129 |
| - |
130 |
| - DeviceAuthorizationGrantFlow deviceAuthorizationGrantFlow = new DeviceAuthorizationGrantFlow(this.mockMvc); |
131 |
| - deviceAuthorizationGrantFlow.setUsername("user"); |
132 |
| - deviceAuthorizationGrantFlow.addScope("message.read"); |
133 |
| - deviceAuthorizationGrantFlow.addScope("message.write"); |
134 |
| - |
135 |
| - Map<String, Object> deviceAuthorizationResponse = deviceAuthorizationGrantFlow.authorize(registeredClient); |
136 |
| - String userCode = (String) deviceAuthorizationResponse.get(OAuth2ParameterNames.USER_CODE); |
137 |
| - assertThatAuthorization(userCode, OAuth2ParameterNames.USER_CODE).isNotNull(); |
138 |
| - assertThatAuthorization(userCode, null).isNotNull(); |
139 |
| - |
140 |
| - String deviceCode = (String) deviceAuthorizationResponse.get(OAuth2ParameterNames.DEVICE_CODE); |
141 |
| - assertThatAuthorization(deviceCode, OAuth2ParameterNames.DEVICE_CODE).isNotNull(); |
142 |
| - assertThatAuthorization(deviceCode, null).isNotNull(); |
143 |
| - |
144 |
| - String state = deviceAuthorizationGrantFlow.submitCode(userCode); |
145 |
| - assertThatAuthorization(state, OAuth2ParameterNames.STATE).isNotNull(); |
146 |
| - assertThatAuthorization(state, null).isNotNull(); |
147 |
| - |
148 |
| - deviceAuthorizationGrantFlow.submitConsent(registeredClient, state, userCode); |
149 |
| - |
150 |
| - Map<String, Object> tokenResponse = deviceAuthorizationGrantFlow.getTokenResponse(registeredClient, deviceCode); |
151 |
| - String accessToken = (String) tokenResponse.get(OAuth2ParameterNames.ACCESS_TOKEN); |
152 |
| - assertThatAuthorization(accessToken, OAuth2ParameterNames.ACCESS_TOKEN).isNotNull(); |
153 |
| - assertThatAuthorization(accessToken, null).isNotNull(); |
154 |
| - |
155 |
| - String refreshToken = (String) tokenResponse.get(OAuth2ParameterNames.REFRESH_TOKEN); |
156 |
| - assertThatAuthorization(refreshToken, OAuth2ParameterNames.REFRESH_TOKEN).isNotNull(); |
157 |
| - assertThatAuthorization(refreshToken, null).isNotNull(); |
158 |
| - |
159 |
| - String scopes = (String) tokenResponse.get(OAuth2ParameterNames.SCOPE); |
160 |
| - OAuth2AuthorizationConsent authorizationConsent = this.authorizationConsentService.findById( |
161 |
| - registeredClient.getId(), "user"); |
162 |
| - assertThat(authorizationConsent).isNotNull(); |
163 |
| - assertThat(authorizationConsent.getScopes()).containsExactlyInAnyOrder( |
164 |
| - StringUtils.delimitedListToStringArray(scopes, " ")); |
165 |
| - } |
166 |
| - |
167 | 120 | private ObjectAssert<OAuth2Authorization> assertThatAuthorization(String token, String tokenType) {
|
168 | 121 | return assertThat(findAuthorization(token, tokenType));
|
169 | 122 | }
|
|
0 commit comments