|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2019 the original author or authors. |
|
|
|
* Copyright 2002-2022 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -86,11 +86,14 @@ public class DefaultPasswordTokenResponseClientTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void getTokenResponseWhenSuccessResponseThenReturnAccessTokenResponse() throws Exception { |
|
|
|
public void getTokenResponseWhenSuccessResponseThenReturnAccessTokenResponse() throws Exception { |
|
|
|
String accessTokenSuccessResponse = "{\n" + |
|
|
|
// @formatter:off
|
|
|
|
" \"access_token\": \"access-token-1234\",\n" + |
|
|
|
String accessTokenSuccessResponse = "{\n" |
|
|
|
" \"token_type\": \"bearer\",\n" + |
|
|
|
+ " \"access_token\": \"access-token-1234\",\n" |
|
|
|
" \"expires_in\": \"3600\"\n" + |
|
|
|
+ " \"token_type\": \"bearer\",\n" |
|
|
|
"}\n"; |
|
|
|
+ " \"expires_in\": \"3600\",\n" |
|
|
|
|
|
|
|
+ " \"scope\": \"read write\"\n" |
|
|
|
|
|
|
|
+ "}\n"; |
|
|
|
|
|
|
|
// @formatter:on
|
|
|
|
this.server.enqueue(jsonResponse(accessTokenSuccessResponse)); |
|
|
|
this.server.enqueue(jsonResponse(accessTokenSuccessResponse)); |
|
|
|
|
|
|
|
|
|
|
|
Instant expiresAtBefore = Instant.now().plusSeconds(3600); |
|
|
|
Instant expiresAtBefore = Instant.now().plusSeconds(3600); |
|
|
|
@ -123,11 +126,14 @@ public class DefaultPasswordTokenResponseClientTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void getTokenResponseWhenClientAuthenticationPostThenFormParametersAreSent() throws Exception { |
|
|
|
public void getTokenResponseWhenClientAuthenticationPostThenFormParametersAreSent() throws Exception { |
|
|
|
String accessTokenSuccessResponse = "{\n" + |
|
|
|
// @formatter:off
|
|
|
|
" \"access_token\": \"access-token-1234\",\n" + |
|
|
|
String accessTokenSuccessResponse = "{\n" |
|
|
|
" \"token_type\": \"bearer\",\n" + |
|
|
|
+ " \"access_token\": \"access-token-1234\",\n" |
|
|
|
" \"expires_in\": \"3600\"\n" + |
|
|
|
+ " \"token_type\": \"bearer\",\n" |
|
|
|
"}\n"; |
|
|
|
+ " \"expires_in\": \"3600\",\n" |
|
|
|
|
|
|
|
+ " \"scope\": \"read\"\n" |
|
|
|
|
|
|
|
+ "}\n"; |
|
|
|
|
|
|
|
// @formatter:on
|
|
|
|
this.server.enqueue(jsonResponse(accessTokenSuccessResponse)); |
|
|
|
this.server.enqueue(jsonResponse(accessTokenSuccessResponse)); |
|
|
|
|
|
|
|
|
|
|
|
ClientRegistration clientRegistration = this.clientRegistrationBuilder |
|
|
|
ClientRegistration clientRegistration = this.clientRegistrationBuilder |
|
|
|
@ -186,6 +192,22 @@ public class DefaultPasswordTokenResponseClientTests { |
|
|
|
assertThat(accessTokenResponse.getAccessToken().getScopes()).containsExactly("read"); |
|
|
|
assertThat(accessTokenResponse.getAccessToken().getScopes()).containsExactly("read"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void getTokenResponseWhenSuccessResponseDoesNotIncludeScopeThenAccessTokenHasNoScope() { |
|
|
|
|
|
|
|
// @formatter:off
|
|
|
|
|
|
|
|
String accessTokenSuccessResponse = "{\n" |
|
|
|
|
|
|
|
+ " \"access_token\": \"access-token-1234\",\n" |
|
|
|
|
|
|
|
+ " \"token_type\": \"bearer\",\n" |
|
|
|
|
|
|
|
+ " \"expires_in\": \"3600\"\n" |
|
|
|
|
|
|
|
+ "}\n"; |
|
|
|
|
|
|
|
// @formatter:on
|
|
|
|
|
|
|
|
this.server.enqueue(jsonResponse(accessTokenSuccessResponse)); |
|
|
|
|
|
|
|
OAuth2PasswordGrantRequest passwordGrantRequest = new OAuth2PasswordGrantRequest( |
|
|
|
|
|
|
|
this.clientRegistrationBuilder.build(), this.username, this.password); |
|
|
|
|
|
|
|
OAuth2AccessTokenResponse accessTokenResponse = this.tokenResponseClient.getTokenResponse(passwordGrantRequest); |
|
|
|
|
|
|
|
assertThat(accessTokenResponse.getAccessToken().getScopes()).isEmpty(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void getTokenResponseWhenErrorResponseThenThrowOAuth2AuthorizationException() { |
|
|
|
public void getTokenResponseWhenErrorResponseThenThrowOAuth2AuthorizationException() { |
|
|
|
String accessTokenErrorResponse = "{\n" + |
|
|
|
String accessTokenErrorResponse = "{\n" + |
|
|
|
|