I Designed a login page for SSO(Single Sign-On) by angular and the services for login developed separately by spring boot framework.
In the angular app, when submitted login form, login service call with post-HttpMethod by HttpClient module. In login service if username and password be correct then in the result of login service, set response status to 302 and add a specific URL to the header of the response. in this scenario I expect to browser redirect to specific URL, but this is not happening.
I trace request and response in Firefox as the same as the attached picture .
I change the Location header of response, and saw that the redirection is not doing(just login request and option request done), below picture is request trace.
You can follow these five steps to fix HTTP 302 errors on your website: Determine whether the redirects are appropriate or not by examining the URLs that are issuing the 302 redirects. Check your plugins to make sure any redirect settings are valid. Ensure that your WordPress URL settings are configured correctly.
Using a XMLHttpRequest in async mode, the redirects are followed and it works as expected,; but in synchronous mode it fails.
What is an HTTP 302? The 302 status code is a redirection message that occurs when a resource or page you're attempting to load has been temporarily moved to a different location. It's usually caused by the web server and doesn't impact the user experience, as the redirect happens automatically.
I suspect your requests are XHR requests. If so, the browser follows them in the handler but won't navigate the full page to the redirect location.
If you want to emulate what happens when a redirect is sent for a full page request, you may want to change your backend so that it returns a 200 with the target location of the original redirect in the payload, and then reload the page to that location (something like window.location = payload.redirectLocation
).
You can also get rid of the redirect, let the backend return 200 or 401 depending on the authentication success, then navigate with the angular router.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With