2015-05-08 28 views
0

我試圖實現與twitter的衛星登錄。 我下面就以satellizer庫的例子,等客戶端我做到以下幾點:Angularjs衛星Twitter的登錄CORS錯誤重定向

$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. 

但是,當我得到重定向到/驗證URL我得到一個錯誤CORS:

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin is therefore not allowed access. 

我看他們的PHP/Laravel例子,他們使用重定向,但對我來說是不行的ING。

我該如何解決這個問題?

回答

0

您需要在您的index.php文件中添加Access-Control-Allow-Origin標頭。 在服務器端開放的index.php和<?php後添加此行:

header("Access-Control-Allow-Origin: *"); 
+0

或者更好的,只添加,你會使用的域。 – pietrovismara