|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2018 the original author or authors. |
| 2 | + * Copyright 2002-2020 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -96,6 +96,39 @@ public void readInternalWhenSuccessfulTokenResponseThenReadOAuth2AccessTokenResp
|
96 | 96 |
|
97 | 97 | }
|
98 | 98 |
|
| 99 | + // gh-6463 |
| 100 | + @Test |
| 101 | + public void readInternalWhenSuccessfulTokenResponseWithObjectThenReadOAuth2AccessTokenResponse() { |
| 102 | + String tokenResponse = "{\n" + |
| 103 | + " \"access_token\": \"access-token-1234\",\n" + |
| 104 | + " \"token_type\": \"bearer\",\n" + |
| 105 | + " \"expires_in\": 3600,\n" + |
| 106 | + " \"scope\": \"read write\",\n" + |
| 107 | + " \"refresh_token\": \"refresh-token-1234\",\n" + |
| 108 | + " \"custom_object_1\": {\"name1\": \"value1\"},\n" + |
| 109 | + " \"custom_object_2\": [\"value1\", \"value2\"],\n" + |
| 110 | + " \"custom_parameter_1\": \"custom-value-1\",\n" + |
| 111 | + " \"custom_parameter_2\": \"custom-value-2\"\n" + |
| 112 | + "}\n"; |
| 113 | + |
| 114 | + MockClientHttpResponse response = new MockClientHttpResponse( |
| 115 | + tokenResponse.getBytes(), HttpStatus.OK); |
| 116 | + |
| 117 | + OAuth2AccessTokenResponse accessTokenResponse = this.messageConverter.readInternal( |
| 118 | + OAuth2AccessTokenResponse.class, response); |
| 119 | + |
| 120 | + assertThat(accessTokenResponse.getAccessToken().getTokenValue()).isEqualTo("access-token-1234"); |
| 121 | + assertThat(accessTokenResponse.getAccessToken().getTokenType()).isEqualTo(OAuth2AccessToken.TokenType.BEARER); |
| 122 | + assertThat(accessTokenResponse.getAccessToken().getExpiresAt()).isBeforeOrEqualTo(Instant.now().plusSeconds(3600)); |
| 123 | + assertThat(accessTokenResponse.getAccessToken().getScopes()).containsExactly("read", "write"); |
| 124 | + assertThat(accessTokenResponse.getRefreshToken().getTokenValue()).isEqualTo("refresh-token-1234"); |
| 125 | + assertThat(accessTokenResponse.getAdditionalParameters()).containsExactly( |
| 126 | + entry("custom_object_1", "{name1=value1}"), |
| 127 | + entry("custom_object_2", "[value1, value2]"), |
| 128 | + entry("custom_parameter_1", "custom-value-1"), |
| 129 | + entry("custom_parameter_2", "custom-value-2")); |
| 130 | + } |
| 131 | + |
99 | 132 | @Test
|
100 | 133 | public void readInternalWhenConversionFailsThenThrowHttpMessageNotReadableException() {
|
101 | 134 | Converter tokenResponseConverter = mock(Converter.class);
|
|
0 commit comments