Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: OpenID Connect - How to get JWT Token
Hi all,
I have a Liferay 7.1.2-ga3 instance configured with SSO using an OpenID Connect provider: everything works as expected.
To avoid a new call to the Authorization server, I have to send the token back to the client and call an API which is not served by Liferay: how can I get the OAuth token from Liferay ?
Thanks in advance.
I have a Liferay 7.1.2-ga3 instance configured with SSO using an OpenID Connect provider: everything works as expected.
To avoid a new call to the Authorization server, I have to send the token back to the client and call an API which is not served by Liferay: how can I get the OAuth token from Liferay ?
Thanks in advance.
I'll give this one a shot.
First, let me see if I undersrtand what you are asking. You are saying you configured the login for OpenID. When the user goes to your site and logs in, it redirects correctly, the user authenticates with OpenID and then is redirected back to Liferay -- at which point they are logged in.
You want to intercept the login process, after openID but before Liferay to do a secondary call or something? Is that it?
If I have read this and interpreted it correctly then I think you might want to provice a service override for the class
.. where your class will have a higher service ranking. That will allow your to inject whatever custom logic you need. Sadly the package with this class is internal so you can't extend it unless you modify the scope on the module -- alternatively you can use the source as is as a baseline in your custom service and then make the changes you need.
If I have totally misunderstood your question, try to clarify for me and I'll try again
Also note that other OpenId classes might give you some additional hints that help. For example, in the OpenIdConnectAustoLogin class you can see that ther eis a check for a session attribute. Normally this attribute is set as part of the authentication process (the first time it occurs) so taht in future the auto login can take over.
First, let me see if I undersrtand what you are asking. You are saying you configured the login for OpenID. When the user goes to your site and logs in, it redirects correctly, the user authenticates with OpenID and then is redirected back to Liferay -- at which point they are logged in.
You want to intercept the login process, after openID but before Liferay to do a secondary call or something? Is that it?
If I have read this and interpreted it correctly then I think you might want to provice a service override for the class
com.liferay.login.authentication.openid.web.internal.portlet.action.OpenIdLoginMVCActionCommand.. where your class will have a higher service ranking. That will allow your to inject whatever custom logic you need. Sadly the package with this class is internal so you can't extend it unless you modify the scope on the module -- alternatively you can use the source as is as a baseline in your custom service and then make the changes you need.
If I have totally misunderstood your question, try to clarify for me and I'll try again
Also note that other OpenId classes might give you some additional hints that help. For example, in the OpenIdConnectAustoLogin class you can see that ther eis a check for a session attribute. Normally this attribute is set as part of the authentication process (the first time it occurs) so taht in future the auto login can take over.
...
HttpSession httpSession = request.getSession(false);
if (httpSession == null) {
return null;
}
OpenIdConnectSession openIdConnectSession =
(OpenIdConnectSession)httpSession.getAttribute(
OpenIdConnectWebKeys.OPEN_ID_CONNECT_SESSION);
if (openIdConnectSession == null) {
return null;
}
OpenIdConnectFlowState openIdConnectFlowState =
openIdConnectSession.getOpenIdConnectFlowState();
...
Hi Andrew,
that's exactly what I'm looking for.
The OpenIdConnectServiceHandlerImpl.class set the session attribute after the login process complets in the requestAuthentication() method: link to github here.
The problem is that OpenIdConnectSession class is in the internal package and I don't think is available outside the bundle and is not possible to call getAccessToken().
How can I access the information I need ? Maybe by reflection ?
Thanks in advance.
that's exactly what I'm looking for.
The OpenIdConnectServiceHandlerImpl.class set the session attribute after the login process complets in the requestAuthentication() method: link to github here.
httpSession.setAttribute(OpenIdConnectWebKeys.OPEN_ID_CONNECT_SESSION, openIdConnectSession);The problem is that OpenIdConnectSession class is in the internal package and I don't think is available outside the bundle and is not possible to call getAccessToken().
How can I access the information I need ? Maybe by reflection ?
Thanks in advance.
You could maybe use reflection, OR .. you could leverage the Genius of one David Nebinger:
https://community.liferay.com/blogs/-/blogs/fixing-module-package-access-modifiers
I'd be inclined to try David's solution first -- Ilike solutions that allow you to control the on/off switch when they are things that are not standard Liferay implementations.
https://community.liferay.com/blogs/-/blogs/fixing-module-package-access-modifiers
I'd be inclined to try David's solution first -- Ilike solutions that allow you to control the on/off switch when they are things that are not standard Liferay implementations.