You will need a URL to the URL before redirecting to your CAS service. When a call returns from a service, you must decode it and redirect it in your application.
If you use Java or .NET or something similar, you can handle all this outside of your angular application with a filter / servlet.
But here is the main idea. In your example, your angular application is located at http://angularapp.com/ .
User request page http://angularapp.com/#/page=bannanas , which must be redirected to the CAS server to log in. You must encode this URL and pass it as a request parameter, for example http://your-cas-site/login?returnUrl=http%3A%2F%2Fangularapp.com%2F%23%2Fpage%3Dbannanas
CAS handles authentication and redirects your application back.
In your application, write a $http interceptor that monitors the returnUrl request returnUrl . When you find it, decode returnUrl=http%3A%2F%2Fangularapp.com%2F%23%2Fpage%3Dbannanas and redirect to it: http://angularapp.com/#/page=bannanas
It can also be processed externally by a filter if your application server supports this. (I did this in Java for my application, but .NET and most other servers support the same thing.)
-
Adding this sample code as requested. Here is my auth filter that handles redirects to the login page.
import java.io.IOException; import java.net.URLEncoder; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class LoginRedirect implements Filter { @Override public void destroy() { } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpServletRequest = (HttpServletRequest) request; HttpServletResponse httpServletResponse = (HttpServletResponse) response;
source share