从一个域重定向到另一个域时,被CORS策略阻止

时间:2019-03-23 06:34:21

标签: java cors angular7 spring-security-oauth2

我正在为我的微服务应用程序设置一个带有自定义登录页面的spring-security-oauth2服务器。我已使用angular设计了“登录”页面。我的网关在端口8761上运行,而我的oauth2服务器在端口9092上运行。 登录页面位于http://localhost:9092/login上。 当我单击网关上的登录名时,我正在对OAuth服务器进行如下调用。

http://localhost:9092/oauth/authorize?client_id=ClientId&redirect_uri=http://localhost:8761/login&response_type=code&scope=user_info%20openid&state=YuHxQ6

如果OAuth服务器尚未登录,则重定向到登录页面,并且在输入有效凭据后可以登录。 到目前为止,一切都很好。但是,当oAuth服务器使用状态和代码(http://localhost:8761/login?code=awfa94&state=YuHxQ6)重定向到注册表时,CORS策略被阻止,并显示以下错误。

Access to XMLHttpRequest at 'http://localhost:8761/login?code=awfa94&state=YuHxQ6' (redirected from 'http://localhost:9092/login') from origin 'http://localhost:9092' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

我在两个应用程序中都允许带有值*的源,标头和方法。我不明白为什么CORS政策会阻止重定向请求。

当我使用spring默认登录页面重定向时,很有趣。

0 个答案:

没有答案
相关问题