如何使用jQuery或纯JavaScript将用户从一个页面重定向到另一个页面?
我在SO上提到了这个问题:Google oauth 400响应:请求的资源上没有'Access-Control-Allow-Origin'标头, 但建议的解决方案是使用 隐式授权流的Javascript Web应用程序。
我的设置是这样的,我的前端基于angular 4构建,但是我打包并将其与rest api一起部署在同一服务器上。是的,我正在遵循服务器端Web应用程序流:https : //developers.google.com/identity/protocols/OAuth2WebServer (在下面的示例中,服务器端口为8300)
我已将http:// localhost:8300授权为Javascript来源,并从一个有角度的应用程序向驻留在http:// localhost:8300 / auth / oauth / test上的rest api发出了请求, 但仍然出现CORS错误:
无法加载 https://accounts.google.com/o/oauth2/v2/auth?client_id=568176070083-1lc20949a0q58l0rhmq93n95kvu8s5o6.apps.googleusercontent.com&redirect_uri=http://localhost:8300/auth/myauth/oauth/callback&response_type=code = https://www.googleapis.com/auth/userinfo.email%20https://www.googleapis.com/auth/userinfo.profile&state=EUTZF8:标头上没有'Access-Control-Allow-Origin'标头要求的资源。因此,不允许访问源' http:// localhost:8300 '。
我的问题是:
如果这是相关的,我正在做角度获取请求,如:
loginWithGoogle(){
console.log(" Login with oauth2 ");
let oauthUrl = "http://localhost:8300/auth/oauth/test";
return this.http.get(oauthUrl)
.subscribe(
res => {
this.onSuccess(res);
}, error => …Run Code Online (Sandbox Code Playgroud)