Legacy Knowledge Base
Published Sep. 10, 2025

Spring Boot Client Extension fails with [invalid_token_response] An error occurred while attempting to retrieve the OAuth 2.0

Written By

Rita Schaff

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

Legacy Article

You are viewing an article from our legacy "FastTrack" publication program, made available for informational purposes. Articles in this program were published without a requirement for independent editing or verification and are provided"as is" without guarantee.

Before using any information from this article, independently verify its suitability for your situation and project.

Issue

  • We have a Spring Boot extension client that interacts with Liferay APIs and makes this OAuth2 challenge: 

    OAuth2AccessToken oAuth2AccessToken = liferayOAuth2AccessTokenManager.getOAuth2AccessToken(clientRegistrationId);
    
  • When we launch the Spring Boot application via bootRun, the OAuth2 Challenge completes without issues. However, when launching it via java -jar spring-boot-client-extension.jar, we receive this error:

    DEBUG 80178 --- [main]            : HTTP POST http://localhost:8080/o/oauth2/token
    DEBUG 80178 --- [main]            : Accept=[application/json, application/*+json]
    DEBUG 80178 --- [main]            : Writing [{grant_type=[client_credentials], client_id=[id-da997878-ba98-79d5-d494-9fa68e7daf0], client_secret=[<secret>]}] as "application/x-www-form-urlencoded;charset=UTF-8"
    DEBUG 80178 --- [main]            : Response 401 UNAUTHORIZED
    ERROR 80178 --- [main]     : Error during the import : [invalid_token_response] An error occurred while attempting to retrieve the OAuth 2.0 Access Token Response: 401 : [no body]
    

Environment

  • Liferay DXP with Client Extensions

Resolution

  • Running the task via bootRun sets two environment variables on the process: LIFERAY_ROUTES_DXP and LIFERAY_ROUTES_CLIENT_EXTENSION. These point to the routes directories, which hold the client extension's required OAuth2 and Liferay connection details.
  • When running the jar directly, required steps depend on your deployment model:
    • Liferay SaaS: These environment variables are set automatically (no additonal actions are required).
    • Liferay PaaS: Set the two environment variables manually before starting the Client Extension process. See Deploying Microservice Client Extensions to Liferay PaaS for more information.
    • Liferay Self-Hosted: Set the two environment variables before starting the java process, for example in a shell script.
      • By default, LIFERAY_ROUTES_DXP points to [Liferay Home]/routes/default/dxp and LIFERAY_ROUTES_CLIENT_EXTENSION points to [Liferay Home]/routes/default/[client extension project name].

Additional Information

  • If the client extension microservice runs on a different host than Liferay, you must also share the $[Liferay Home]/routes directory across systems (using something like NFS, sshfs, etc.)

  • Working with Client Extensions
Did this article resolve your issue ?

Legacy Knowledge Base