You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I finally succeeded to resolve this problem thank's to @Grauzone's pull-request
You must add these methods in your SecurityConfig class :
private OAuth2UserService<OAuth2UserRequest, OAuth2User> oauth2UserService() {
RestTemplate restTemplate = new RestTemplate();
restTemplate.setErrorHandler(new OAuth2ErrorResponseErrorHandler());
enhanceJsonMessageConverter(restTemplate);
customOAuth2UserService.setRestOperations(restTemplate);
return customOAuth2UserService;
}
private void enhanceJsonMessageConverter(RestTemplate restTemplate) {
// NOTE:
// Facebook's UserInfo API -> https://graph.facebook.com/me
// returns "text/javascript; charset=UTF-8" for the "content-type" response header
// even though the content is JSON. This is not correct and should be reported to Facebook to fix.
//
// This is a temporary workaround that adds "text/javascript; charset=UTF-8"
// as a supported MediaType in MappingJackson2HttpMessageConverter,
// which is used to convert the UserInfo response to a Map.
HttpMessageConverter<?> jsonMessageConverter = restTemplate.getMessageConverters().stream()
.filter(c -> c instanceof MappingJackson2HttpMessageConverter)
.findFirst()
.orElse(null);
if (jsonMessageConverter == null) {
return;
}
List<MediaType> supportedMediaTypes = new ArrayList<>(jsonMessageConverter.getSupportedMediaTypes());
supportedMediaTypes.add(MediaType.valueOf("text/javascript;charset=UTF-8"));
((AbstractHttpMessageConverter) jsonMessageConverter).setSupportedMediaTypes(supportedMediaTypes);
}
And then replace .userService(customOAuth2UserService) by .userService(oauth2UserService())
Hi!
I have the fresh code base up and running with everything configured, but when I try to Log in or Sign up I get this error log:
org.springframework.http.converter.HttpMessageNotReadableException: An error occurred reading the OAuth 2.0 Error: JSON parse error: Cannot deserialize instance of
java.lang.Stringout of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of
java.lang.Stringout of START_OBJECT token at [Source: (sun.net.www.protocol.http.HttpURLConnection$HttpInputStream); line: 1, column: 10] (through reference chain: java.util.LinkedHashMap["error"]); nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize instance of
java.lang.Stringout of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of
java.lang.Stringout of START_OBJECT token at [Source: (sun.net.www.protocol.http.HttpURLConnection$HttpInputStream); line: 1, column: 10] (through reference chain: java.util.LinkedHashMap["error"])
Maybe Facebook sending another format back and an update needed.
Hint: Google login/signup working fine...
Can you please fix this problem?
Thank you very much!
The text was updated successfully, but these errors were encountered: