-2

I'm developing a restful API with laravel. Authorization is done using a SECRET_KEY & PUBLIC_KEY as shown in the sample request code below.

How do i retrieve the Authorization header key value from the Request?

I would also appreciate links to any resources that would guide me through better implementation & best practice in creating a Restful API with Laravel.


 $curl = curl_init();
           $url = "http://api.example.com/v1/users";

           $secretKey = env('SECRET_KEY');
           $publicKey = env('PUBLIC_KEY');

           $firstName = "John";
           $lastName = "Doe";
           $email = "example@gmail.com";


            curl_setopt_array($curl, array(
               CURLOPT_URL => $url,
               CURLOPT_RETURNTRANSFER => true,
               CURLOPT_ENCODING => "",
               CURLOPT_MAXREDIRS => 10,
               CURLOPT_TIMEOUT => 0,
               CURLOPT_FOLLOWLOCATION => true,
               CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
               CURLOPT_CUSTOMREQUEST => "POST",
               CURLOPT_POSTFIELDS => "{\r\n  \"firstName\": \"$firstName\",\r\n  \"lastName\": \"$lastName\",\r\n  \"email\": \"$email\",\r\n  \"secretKey\": \"$secretKey\",\r\n}",
               CURLOPT_HTTPHEADER => array(
                   "Content-Type: application/json",
                   'Authorization: Bearer ' . $publicKey,
               ),
           ));

           $response = curl_exec($curl);

           curl_close($curl);
astroame
  • 389
  • 1
  • 8
  • 24

2 Answers2

0

You can check the official documentaion : https://laravel.com/docs/7.x/eloquent-resources#introduction

Also you might want to use a tool like Postman to test your API easily.

user3813360
  • 566
  • 9
  • 25
0

The request() helper contains everything from the request. Just dd(request()->header()) to see the full list of the request headers.

glam
  • 116
  • 2
  • 5