Angularjs Satellizer Twitter login CORS error on redirect

时间:2015-05-08 10:01:54

标签: php angularjs twitter satellizer

I'm trying to implement a login with satellizer for twitter. I'm following the examples on the satellizer repository, so on client-side i do the following:

public static void trustSelfSignedSSL() {
    try {
        SSLContext ctx = SSLContext.getInstance("TLS");
        X509TrustManager tm = new X509TrustManager() {

            @Override
            public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
            }

            @Override
            public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
            }

            @Override
            public X509Certificate[] getAcceptedIssuers() {
                return null;
            }
        };
        ctx.init(null, new TrustManager[] { tm }, null);
        SSLContext.setDefault(ctx);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

And on server-side i follow their login flow for oauth 1.0:

 #include <irrlicht.h>
 #include "driverChoice.h"
 #include <opencv/cv.h>
 #include <opencv/cxcore.h>
 #include <opencv/highgui.h>
 #include <time.h>
 #include <sys/timeb.h> 
 #include <opencv2\highgui\highgui.hpp>
 #include <IGUIEnvironment.h>

 using namespace cv;
 using namespace irr;
 using namespace core;
 using namespace scene;
 using namespace video;
 using namespace io;
 using namespace gui;

 #ifdef _MSC_VER
 #pragma comment(lib, "Irrlicht.lib")
 #endif

 #ifdef _IRR_WINDOWS_
 #pragma comment(lib, "Irrlicht.lib")
 #pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
 #endif


 int main()
 {
 IrrlichtDevice *device = createDevice(video::EDT_OPENGL, dimension2d<s32>     (640 , 480), 16, false, true /* shadow */, false);
if (!device)
    return 1;
device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* guienv = device->getGUIEnvironment();
ITexture* frame_tex = driver->addTexture(vector2d<s32>(640, 480), "video_stream");
guienv->addStaticText(L"Hello World! This is the Irrlicht Software renderer!",
    rect<s32>(10,10,260,22), true);
IAnimatedMesh* mesh = smgr->getMesh("E:/Akshay/VS2012Projects/IrrlichtDemoApp/IrrlichtDemoApp/ratamahatta.md2");
if (!mesh)
{
    device->drop();
    return 1;
}
IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
if (node)
{
    node->setMaterialFlag(EMF_LIGHTING, false);
    node->setMD2Animation(scene::EMAT_STAND);
    node->setMaterialTexture( 0, driver->getTexture("E:/Akshay/VS2012Projects/IrrlichtDemoApp/IrrlichtDemoApp/ctf_r.png") );
}   
smgr->addCameraSceneNode(0, vector3df(20,30,-50), vector3df(0,5,0));
while(device->run())
{
VideoCapture capture(0);
Mat camera_frame;


if( cv::waitKey(50) >= 0 ) break;
if( !capture.grab() )
{
    std::cout << "Unable to grab camera frame\n";
}
capture >> camera_frame;

if( ! camera_frame.empty() )
{
    //exception here
    unsigned char *tex_buf = (unsigned char*)frame_tex->lock();
    unsigned char *frame_buf = camera_frame.data;
    // Convert from RGB to RGBA
    for(int y=0; y < camera_frame.rows; y++) {
        for(int x=0; x < camera_frame.cols; x++) {
            *(tex_buf++) = *(frame_buf++);
            *(tex_buf++) = *(frame_buf++);
            *(tex_buf++) = *(frame_buf++);
            *(tex_buf++) = 255;
        }
    }
    frame_tex->unlock();

    driver->beginScene(true, true, SColor(255,100,101,140));

    driver->draw2DImage(frame_tex, core::rect<s32>(0,0,640,480),
        core::rect<s32>(0,0,480,640));

    smgr->drawAll();
    guienv->drawAll();

    driver->endScene();
}
}

device->drop();
}

But, when i get to redirect to the /authenticate URL i get a CORS error:

$auth.authenticate('twitter')
     .then(function (res) {
           console.log(res);
     });

I looked on their example for php/Laravel and they use redirect, but for me is not working.

How can i solve this problem?

1 个答案:

答案 0 :(得分:0)

您需要在index.php文件中添加Access-Control-Allow-Origin标头。 在服务器端打开index.php并在<?php之后添加此行:

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