0

I'm pretty new to Basic HTTP Authentication (PHP) and would like to know how I can authenticate myself on the api of another website. I have a username and password to get access to the external api. Username is in $this->id, password is in $this->key.

This is the api url to get the data I want: http://api.medipim.be/v2/web/product/print/0011890?language=nl&user_id='.$this->id.'&validation='.$this->key

How do I authenticate myself? Any options via curl?

2 Answers 2

1

Otto's answer is generally the right way to do authentication for the medipim api using php & curl. However, the api call in question does not require http authentication; the request is authenticated using a token based on your credentials. This way the url can be passed to a (web)client without exposing your api key. We've recently updated the documentation for this call, so you might want to have another look.

Sign up to request clarification or add additional context in comments.

Comments

0

Yes, CURL can set the user and pass for you:

curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");

Replace $username with $this->id and similar with password

2 Comments

1) How do I handle the url of the external site? Since the url also requires the variables. 2) Does $username:$password have to be within the ""?
1) It would be strange to provide them both in the URL and inside the AUTH headers. Please check the documentation of the api 2) well you need to concatenate them with a colon in between. You could also write $this->id . ':' . $this->key

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.