samedi 18 juin 2016

Authorization token in php

When a user login to a system web service will send a authorization token as follows I need to add these tokes as a header for all the get request that user will make after login I have written following code using curl through a not found exception can anyone help me to find a solution

token:{"user" :"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjMsImlzcyI6Imh0dHA6XC9cL2xvY2FsaG9zdDo4MDAwXC9hcGlcL2F1dGhcL2F1dGhlbnRpY2F0ZSIsImlhdCI6MTQ2NjIzNTc1OSwiZXhwIjoxNDY2MjM5MzU5LCJuYmYiOjE0NjYyMzU3NTksImp0aSI6ImJjZmExYjc5OGYyYTY2MTAyMWY2OTM3NTc3MTkyZTNhIn0.ai91pavOiqs_41bFD5A9X2IsoniP1FHvRswR6coTwXc"}

   $authorization = "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjMsImlzcyI6Imh0dHA6XC9cL2xvY2FsaG9zdDo4MDAwXC9hcGlcL2F1dGhcL2F1dGhlbnRpY2F0ZSIsImlhdCI6MTQ2NjIzNTc1OSwiZXhwIjoxNDY2MjM5MzU5LCJuYmYiOjE0NjYyMzU3NTksImp0aSI6ImJjZmExYjc5OGYyYTY2MTAyMWY2OTM3NTc3MTkyZTNhIn0.ai91pavOiqs_41bFD5A9X2IsoniP1FHvRswR6coTwXc";                                                                                
   $ch = curl_init('http://localhost:8000/api/auth/logout');                                                                      
   curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json' , $authorization ));
   curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
   curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
   $result = curl_exec($ch);
   curl_close($ch);
//return json_decode($result);

   return view('checking', ['title' => $result]);



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire