0

I am trying to create a simple OAuth2 Client to access Todoist API features like Todoist Webhook. I am using Spring Boot 3.0 with Spring OAuth2 Client. When get redirected to the access_token this error occurs:

2022-12-30T21:22:41.948-03:00 ERROR 3858 --- [p-nio-80-exec-3] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception

org.springframework.http.converter.HttpMessageNotReadableException: An error occurred reading the OAuth 2.0 Error: JSON parse error: Unexpected character ('<' (code 60)): expected a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
    at org.springframework.security.oauth2.core.http.converter.OAuth2ErrorHttpMessageConverter.readInternal(OAuth2ErrorHttpMessageConverter.java:84) ~[spring-security-oauth2-core-6.0.1.jar:6.0.1]
    at org.springframework.security.oauth2.core.http.converter.OAuth2ErrorHttpMessageConverter.readInternal(OAuth2ErrorHttpMessageConverter.java:48) ~[spring-security-oauth2-core-6.0.1.jar:6.0.1]
    at org.springframework.http.converter.AbstractHttpMessageConverter.read(AbstractHttpMessageConverter.java:199) ~[spring-web-6.0.3.jar:6.0.3]
    at org.springframework.security.oauth2.client.http.OAuth2ErrorResponseErrorHandler.handleError(OAuth2ErrorResponseErrorHandler.java:64) ~[spring-security-oauth2-client-6.0.1.jar:6.0.1]
    at org.springframework.web.client.ResponseErrorHandler.handleError(ResponseErrorHandler.java:63) ~[spring-web-6.0.3.jar:6.0.3]
    at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:915) ~[spring-web-6.0.3.jar:6.0.3]
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:864) ~[spring-web-6.0.3.jar:6.0.3]
    at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:704) ~[spring-web-6.0.3.jar:6.0.3]
    at org.springframework.security.oauth2.client.endpoint.DefaultAuthorizationCodeTokenResponseClient.getResponse(DefaultAuthorizationCodeTokenResponseClient.java:88) ~[spring-security-oauth2-client-6.0.1.jar:6.0.1]
    at org.springframework.security.oauth2.client.endpoint.DefaultAuthorizationCodeTokenResponseClient.getTokenResponse(DefaultAuthorizationCodeTokenResponseClient.java:77) ~[spring-security-oauth2-client-6.0.1.jar:6.0.1]
    at org.springframework.security.oauth2.client.endpoint.DefaultAuthorizationCodeTokenResponseClient.getTokenResponse(DefaultAuthorizationCodeTokenResponseClient.java:56) ~[spring-security-oauth2-client-6.0.1.jar:6.0.1]
    at org.springframework.security.oauth2.client.authentication.OAuth2AuthorizationCodeAuthenticationProvider.authenticate(OAuth2AuthorizationCodeAuthenticationProvider.java:85) ~[spring-security-oauth2-client-6.0.1.jar:6.0.1]
    at org.springframework.security.oauth2.client.authentication.OAuth2LoginAuthenticationProvider.authenticate(OAuth2LoginAuthenticationProvider.java:107) ~[spring-security-oauth2-client-6.0.1.jar:6.0.1]
    at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:182) ~[spring-security-core-6.0.1.jar:6.0.1]

I believe Todoist API is returning an HTML page rather than a the access token and token type but not sure. This is my applications.yml file:

server:
  port: 80
spring:
  security:
    oauth2:
      client:
        registration:
          todoist:
            client-id: ${TODOIST_CLIENT_ID}
            client-secret: ${TODOIST_CLIENT_SECRET}
            scope: data:read_write
            authorization-grant-type: authorization_code
            redirect-uri: "http://localhost/login/oauth2/code/{registrationId}"
            client-authentication-method: post
        provider:
          todoist:
            authorization-uri: https://todoist.com/oauth/authorize
            token-uri: https://todoist.com/oauth/access_token

Is there something wrong with my yaml file? Do I need to create a custom handler for the response from Todoist?

I tried to debug the RestTemplate calls but they do not show me the result of the request with the access tokens.

0 Answers0