Angularjs Satellizer Twitter 登录重定向时出现 CORS 错误
Angularjs Satellizer Twitter login CORS error on redirect
我正在尝试使用 satellizer 为 Twitter 实现登录。
我正在关注 satellizer 存储库中的示例,因此在客户端我执行以下操作:
$auth.authenticate('twitter')
.then(function (res) {
console.log(res);
});
在服务器端,我遵循他们的 oauth 1.0 登录流程:
Client: Open a popup window via $auth.authenticate('provider name').
Client: Unlike OAuth 2.0, you cannot go directly to the authentication screen without a valid request token.
Client: The OAuth 1.0 flow starts with the GET request to /auth/provider inside the popup.
Server: Check if URL contains oauth_token and oauth_verifier parameters.
Sever: Initially it does not, so send an OAuth signed POST request to the /request_token URL.
Server: Redirect to the /authenticate URL with a valid request token.
但是,当我重定向到 /authenticate URL 时,我收到一个 CORS 错误:
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin is therefore not allowed access.
我查看了他们 php/Laravel 的示例,他们使用了重定向,但对我来说不起作用。
我该如何解决这个问题?
您需要在 index.php 文件中添加 Access-Control-Allow-Origin header。
在服务器端打开 index.php 并在 <?php
之后添加此行:
header("Access-Control-Allow-Origin: *");
我正在尝试使用 satellizer 为 Twitter 实现登录。 我正在关注 satellizer 存储库中的示例,因此在客户端我执行以下操作:
$auth.authenticate('twitter')
.then(function (res) {
console.log(res);
});
在服务器端,我遵循他们的 oauth 1.0 登录流程:
Client: Open a popup window via $auth.authenticate('provider name').
Client: Unlike OAuth 2.0, you cannot go directly to the authentication screen without a valid request token.
Client: The OAuth 1.0 flow starts with the GET request to /auth/provider inside the popup.
Server: Check if URL contains oauth_token and oauth_verifier parameters.
Sever: Initially it does not, so send an OAuth signed POST request to the /request_token URL.
Server: Redirect to the /authenticate URL with a valid request token.
但是,当我重定向到 /authenticate URL 时,我收到一个 CORS 错误:
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin is therefore not allowed access.
我查看了他们 php/Laravel 的示例,他们使用了重定向,但对我来说不起作用。
我该如何解决这个问题?
您需要在 index.php 文件中添加 Access-Control-Allow-Origin header。
在服务器端打开 index.php 并在 <?php
之后添加此行:
header("Access-Control-Allow-Origin: *");