Skip to content

Cannot serialize OAuth2AuthenticationToken to JSON #4991

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

Closed
bberto opened this issue Feb 2, 2018 · 4 comments
Closed

Cannot serialize OAuth2AuthenticationToken to JSON #4991

bberto opened this issue Feb 2, 2018 · 4 comments
Assignees
Labels
in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) status: duplicate A duplicate of another issue

Comments

@bberto
Copy link
Contributor

bberto commented Feb 2, 2018

Summary

For a simple app with OIDC login I cannot serialize Principal/OAuth2AuthenticationToken as JSON:

@SpringBootApplication
@RestController
public class WebApplication {

  @RequestMapping("/user")
  public Principal user(Principal user) {
    return user;
  }
  
  public static void main(String[] args) {
    SpringApplication.run(WebApplication.class, args);
  }
  
}

Failed to write HTTP message: org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Unable to convert claim 'iat' to Instant: For input string: "Fri Feb 02 14:05:58 CET 2018"; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Unable to convert claim 'iat' to Instant: For input string: "Fri Feb 02 14:05:58 CET 2018" (through reference chain: org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken["principal"]->org.springframework.security.oauth2.core.oidc.user.DefaultOidcUser["issuedAt"])

Version

Spring Boot 2.0.0.RC1
Spring Security 5.0.1.RELEASE

@jgrandja jgrandja added the in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) label Feb 2, 2018
@jgrandja
Copy link
Contributor

jgrandja commented Feb 2, 2018

Looks like this is a Jackson related issue. Can you ensure the following dependency is included:

<dependency>
    <groupId>com.fasterxml.jackson.datatype</groupId>
    <artifactId>jackson-datatype-jsr310</artifactId>
</dependency>

you might need this as well

<dependency>
    <groupId>com.fasterxml.jackson.datatype</groupId>
    <artifactId>jackson-datatype-jdk8</artifactId>
</dependency>

See the Jackson docs for further info.

Let me know if this resolves your issue.

@bberto
Copy link
Contributor Author

bberto commented Feb 2, 2018

They're both included. I've also tried to update at jackson 2.9.4 without success.

image

I noticed that here claim is a Date, and Long.valueOf raises the NumberFormatException

@rwinch
Copy link
Member

rwinch commented Feb 2, 2018

Thanks for the report @bberto I believe this is a duplicate of #4886

@rwinch
Copy link
Member

rwinch commented Feb 5, 2018

I'm closing this as a duplicate of #4886

@rwinch rwinch closed this as completed Feb 5, 2018
@rwinch rwinch added the status: duplicate A duplicate of another issue label Feb 5, 2018
@rwinch rwinch self-assigned this Feb 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

3 participants