How to use PHP Authorization Header

I am trying to use authorization header to use the vimeo API.

It tells me that I am doing this "Authorization: base" + base64 (client_id + ':' + client_secret), what can I do.

But nowhere on the internet does it tell me what am I actually doing with this code? It's not PHP, but does it go to a PHP file? If so, what function can I use on it after storing it? Does this happen in the htaccess file?

It's very sad how awful any online documentation is.

To summarize, basically what I say is SHOW ME THE CODE

thanks for the help

+3


source to share


2 answers


$api_url = 'http://myapiurl';

$client_id = 'myclientid';
$client_secret = 'myclientsecret';

$context = stream_context_create(array(
    'http' => array(
        'header' => "Authorization: Basic " . base64_encode("$client_id:$client_secret"),
    ),
));

$result = file_get_contents($api_url, false, $context);

      

Links to documentation:



For more complex queries, you can use cURL , but the PHP library implementation is a mess and I prefer to avoid it whenever I can. Guzzle is a library that abstracts a lot of complexity here.

+7


source


Vimeo strongly recommends not writing these authentication systems yourself, but using the official libraries: https://github.com/vimeo/vimeo.php .

If you're looking for your own PHP integration, it depends on the way you make HTTP requests. buzz and curl are both HTTP request libraries and native ways to customize headers ( http://guzzle.readthedocs.org/en/latest/request-options.html#headers and PHP cURL custom headers )



As for the base64 encoding your tokens, use the method base64_encode

( http://php.net/manual/en/function.base64-encode.php )

+1


source







All Articles