I have a public site hosted on AEM. This public site has product pages, if you want to purchase, you have to log-in in order to add to cart and so on. So, basically this site has public pages and same public pages have few more options available if the end user is signed-in.
Now, the challenge here is, how can this be achieved by SAML Auth Handler as it doesn't completely supports IdP initiated auth due to the fact that it'll always come back to the home page of the site after successful authentication because request path cookie will not be set with the origination URL which can be anything.
To simplify here is the use case I want to achieve with SAML Auth Handler:
1) End user comes to a public product page within the site
2) End user clicks on sign-in
3) After successful authentication by IdP, user has redirected to the product page from where he/she initiated sign-in.
I have a work around, which I implemented in AEM 6.2, to have a servlet, serving over secured path(configured at SAML Handler and Sling Auth Service), which takes a parameter as final redirect. Now, sign-in URL will be different based on which page you're visiting on the site, i.e. going to servlet's secured path with final redirect parameter set to the current page. This way, after successful authentication, servlet will redirect to final target which was the origination page.
I don't feel this is a correct approach. I would like to utilize something with lesser custom code and more OOTB. Does anyone has come across the use case I have here and found any better way to deal with it? Is there any better approach available in AEM 6.4 or 6.5 that I might have missed?
Login hook authentication handler will execute before your saml auth handler as it higher ranking than saml and in the request credentials method set the "saml_request_path" cookie pointing to the value "redirect uri or request uri" before wrapping up the request as shown in the sample code.
Note : Saml Authentication handler will do the redirect based on your "saml_request_path /request-path" cookie and if not present it will take you to the page that you configured on saml handler.
Note : if saml_request_path cookie didnt work please try the cookie with the name "request-path"
Sample Method :
public boolean requestCredentials(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)
The IDP initiated login basically takes away the "saml_request_path" cookie. AEM does support IDP Initiated SAML and while using IDP initiated Authentication, you must consult with your IDP to understand how to redirect the user back to the "source" page.
Thank you Prem and Aneet for taking time in responding to my post.
I remember trying out IdP initiated login last year with relay state parameter but that didn't work out or probably I didn't try it out in correct way. I'll check this again and update here. Its a cleaner approach without any custom coding.
I'll fall back to the other method described by Prem in case that doesn't work out.