-
Notifications
You must be signed in to change notification settings - Fork 1.3k
When OAuth2AccessTokenResponse AdditionalParameters contain long data would be truncated #1411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@wanghongzhou I'm not sure I understand the issue you are having. Please provide a minimal sample that reproduces the issue so I can look into it further. |
@jgrandja |
If Jackson is available in the classapth, then As mentioned in previous comment, can you provide a minimal sample or test that reproduces the issue so I can look into it further? |
MappingJackson2HttpMessageConverter is new, I can't to configure Jackson. For example, configure a value of type Long to be converted to a string when serialized. If not configured, the values of type Long are serialized with the JSON, and the values read by JavaScript are truncated. You can refer to this address: |
in HttpMessageConverters.getJsonMessageConverter(), You need to prioritize getting it from the spring container rather than creating a new MappingJackson2HttpMessageConverter,Or provide other ways to customize jackson's behavior |
Still thank you for reading, my code is not good to peel off, in general: If returned token data contained in the value of the Long after serialization into JSON, Javascript to read the value of is wrong, now I am through custom AuthenticationSuccessHandler to modify the behavior of the Jackson serialization, Will the value of the Long when serialized into a string, if you can support custom Jackson's behavior, need not custom AuthenticationSuccessHandler |
As a standard process to bug reporting, we ask the user to provide a minimal example or test that reproduces the issue. Explaining it is not sufficient. I went ahead and wrote a test in Here is the test: @Test
public void writeAccessTokenResponseWithAdditionalParameterLongMax() throws Exception {
Instant expiresAt = Instant.now().plusSeconds(3600);
Set<String> scopes = new LinkedHashSet<>(Arrays.asList("read", "write"));
Map<String, Object> additionalParameters = new HashMap<>();
additionalParameters.put("long-max-value", Long.MAX_VALUE);
// @formatter:off
OAuth2AccessTokenResponse accessTokenResponse = OAuth2AccessTokenResponse.withToken("access-token-1234")
.tokenType(OAuth2AccessToken.TokenType.BEARER)
.expiresIn(expiresAt.toEpochMilli())
.scopes(scopes)
.additionalParameters(additionalParameters)
.build();
// @formatter:on
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
this.accessTokenHttpResponseConverter.write(accessTokenResponse, null, outputMessage);
String tokenResponse = outputMessage.getBodyAsString();
assertThat(tokenResponse).contains("\"access_token\":\"access-token-1234\"");
assertThat(tokenResponse).contains("\"token_type\":\"Bearer\"");
assertThat(tokenResponse).contains("\"scope\":\"read write\"");
assertThat(tokenResponse).contains("\"long-max-value\":" + Long.MAX_VALUE + "");
} Also, the SO post you referenced states the following:
Based on the test above, I'm not able to reproduce the issue. Please provide a test similar to above that reproduces the issue, otherwise this will get closed. |
This is not a spring authorization BUG, this is really a javascript problem, because of this problem exists, so when Jackson serialization I want to serialize the value of type Long into a string return, I hope I can control Jackson serialization. However, Jackson's serialization is currently not configurable. I just hope the spring - authorization can realize configuration of Jackson, rather than directly fixed use new MappingJackson2HttpMessageConverter (), if I can to configuration of Jackson, I don't need to go to the custom implementation AuthenticationSuccessHandler, it is only a suggestion, if you do not not appropriate, please ignore it. Thank you for your reply and attention to this issue. Thank you! |
@wanghongzhou I now understand what you are looking to accomplish. Apologies that it took me long to understand. Instead of allowing to configure Jackson serialization in order to
You can configure this behaviour in a custom Please take a look at gh-1429 as we are looking to address gh-925. You will notice that the new I'm going to close this as a duplicate. Please add any additional comments to gh-925. |
Oauth2AuthenticationSuccessHandler
class invokesOAuth2AccessTokenResponseHttpMessageConverter
transformed to the returned token, WhenOAuth2AccessTokenResponse
additionalParameters
contains Long data return an error value,jsonMessageConverter
is Fixed in OAuth2AccessTokenResponseHttpMessageConverter :Hope to be able to share existing MappingJackson2HttpMessageConverter object in the container
The text was updated successfully, but these errors were encountered: