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 viajava -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
bootRunsets two environment variables on the process:LIFERAY_ROUTES_DXPandLIFERAY_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_DXPpoints to[Liferay Home]/routes/default/dxpandLIFERAY_ROUTES_CLIENT_EXTENSIONpoints to[Liferay Home]/routes/default/[client extension project name].
- By default,
Additional Information
If the client extension microservice runs on a different host than Liferay, you must also share the
$[Liferay Home]/routesdirectory across systems (using something like NFS, sshfs, etc.)- Working with Client Extensions