'AWS Cognito JWT token for current Liferay session not available

I tried this solution to get the configured Cognito token. How to get JWT token for current Liferay session

The login with Cognito works but the extracting token from the session not working for me

I used the same code as mentioned in this post. On further investigation, I found that the openIdConnectSession object is of type class [B
Is there any other configuration required in AWS Cognito or Liferay to have the Cognito token injected successfully in the Liferay session?

epublic void doView(RenderRequest renderRequest, RenderResponse renderResponse)
        throws PortletException, IOException
{
    
    try {
        
         HttpSession session = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(renderRequest)).getSession();
           
         
        OpenIdConnectSession openIdConnectSession =
                   (OpenIdConnectSession)session.getAttribute(
                      OpenIdConnectWebKeys.OPEN_ID_CONNECT_SESSION);
        
        // get the jwtToken from the renderRequest parameter
        String jwtToken = null;
       
        System.out.println(" session attr: " + openIdConnectSession.getClass());
        
        if (session.getAttribute(OpenIdConnectWebKeys.OPEN_ID_CONNECT_SESSION) instanceof OpenIdConnectSession) {
            OpenIdConnectSession openIdConnectSession1 = (OpenIdConnectSession) session.getAttribute(OpenIdConnectWebKeys.OPEN_ID_CONNECT_SESSION);
            jwtToken = openIdConnectSession1.getAccessTokenValue();
        }
            
        System.out.println(" Token :" + jwtToken);
        // do other stuff

        //super.render(renderRequest, renderResponse);
    } catch (Exception e) {
        throw new PortletException(e);
    }
    
}   


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source