1

私は drupal と node.js の初心者です。drupal を node.js サーバーに接続しています。私がやろうとしているのは、node.js サーバーの応答から Cookie を取得することです。これらの Cookie を node.js サーバーへの次の要求に設定する必要があります。

function sample_submit($form, &$form_state) {
  $request_url = "http://localhost/api/authenticate";  //Link to Node.Js server
  $sig =  hash_hmac('sha512', 'secret', 'secret');//hashed the api key using sha512 algoritham
  $options = array(
                'method' => 'POST',
                'data' =>  'apikey='.$sig,//api key for authenticaton between nodejs and drupal application
                'timeout' => 15,
                'headers' => array('Content-Type'=> 'application/x-www-form-urlencoded')
        );
    $result = drupal_http_request($request_url, $options);     
}

node.jsサーバーでAPIキーを使用してリクエストを認証しています。node.js サーバーは、passportjs モジュールを使用してセッション Cookie を作成します。node.js サーバーから Cookie を取得し、次のリクエストで Cookie を渡したいと思います。つまり、上記の関数から Cookie を取得し、以下の関数でリクエストと共に Cookie を送信して、node.js サーバーのみが drupal アプリで認証できるようにします。

function sample_submit1($form, &$form_state) { 
  $request_url = "http://localhost/login";  //Link to Node.Js server
  $options = array(
                'method' => 'GET',
                'timeout' => 15,
                'headers' => array('Content-Type'=> 'application/x-www-form-urlencoded')
        );
    $result = drupal_http_request($request_url, $options);
    drupal_set_message(t($result->data));

これを行う方法またはより良い方法はありますか?これについての洞察は高く評価されます。ありがとうございました。

4

0 に答える 0