Can't authenticate a cURL request despite supplying username and password - php

I have a dev URL that is behind HTTP authentication using a simple .htpasswd file - nothing special about that at all, all standard.
I am trying to hit a URL on that domain via cURL but am getting this message of course:
Unauthorized
This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required.
Apache/2.4.29 (Ubuntu) Server
I have added what I believe to be the correct parameter to authorise the url but with no joy. Just the same message. I have echo'd out the username and password and these are exactly as I would enter into the browser prompt.
What is the next step to debug this?

I have solved this by NOT using curl_setopt_array, instead setting each 3 separately. Cannot currently explain why this is different but it works! :(

Related

How can I get info from a backed server which requires client certificate authentication?

The backedn server URL is https://www.example.com/order/?id=
I am writing the front end to pass order id to this server and display the information I got back.
Server www.example.com requires client certificate authentication.
If I use browser to this URL https://www.example.com/order/?id=123456
I can select my certificate and then get the information I want.
Is there any way I can do this:
Initial page asks the user to select client certificate they wan to use on browser and input order number --> Pass the client certificate andorder number to 'https://www.example.com/order/?id=' to get an result
I've tried using file_get_contents() and cURLs but could not find a way to pass in the client certificate.
---------Update-----------
I've update my Apache virtualHost file and I can have the client certificate information store on the environment now.
$_SERVER['SSL_CLIENT_M_SERIAL']
$_SERVER['SSL_CLIENT_S_DN']
$_SERVER['SSL_CLIENT_V_END']
What I should do to pass these certificate information to the backend server to get through the authentication?

Pinterest API - 403 error when requesting access token on Dreamhost server

I'm using this php wrapper, successfully getting a code from pinterest using the link generated according to the docs:
$loginurl = $pinterest->auth->getLoginUrl($callback_url, array('read_public'));
Then when I run this:
$token = $pinterest->auth->getOAuthToken($_GET['code']);
It works fine on my local server, but when I try to run it on our Dreamhost server, I get:
Pinterest error (code: 403) with message: Forbidden
I looked through the error documentation Pinterest supplies, but I can't find anything relating to 403 errors when retrieving oauth tokens.
The only two places I've seen mention of 403 errors when requesting oauth tokens from Pinterest's API have concluded that Pinterest is blocking the ips or the user agent string.
I've tried manually overriding the user agent string to no avail.
I've tried contacting Pinterest to find out if there is anything I'm missing and they directed me here.
Make sure the Dreamhost server is using an HTTPS URL e.g. is using TLS. That could be the reason why you get a 403.

User Authentication in password grace period

PHP Version 5.3.10
I'm using Apache on a Windows network and when I call $_SERVER['REMOTE_USER'] it works fine until the user enters the password expiry grace period (you have x days until your password expires) when all they see is this message:
Authorization Required The server could not verify that you are authorized to access the document requested. Either you supplied the
wrong credentials (eg bad password), or your browser doesn’t
understand how to supply the credentials required.
Is there any way of catching this and presenting a more helpful message to the user?
Update
Thanks Fred for the useful information. I added the following line to .htaccess
ErrorDocument 401 /401.php
and added 401.php to the same folder as .htaccess and I immediately got the following error when trying to access the site:
Authorization Required This server could not verify that you are
authorized to access the document requested. Either you supplied the
wrong credentials (e.g., bad password), or your browser doesn't
understand how to supply the credentials required.
Additionally, a 401 Authorization Required error was encountered while
trying to use an ErrorDocument to handle the request.
As a test I also added
ErrorDocument 404 /404.php
and was correctly given the alternative page not found message.
I'm not sure what you mean by "Then to catch the error, you would just use a function to write to file". Do you have an example? Following is the code I use to get the user's username:
$domain = $_SERVER['REMOTE_USER'];
$domainarray = explode("\\",$domain);
$username = strtolower ($domainarray[1]);

file_get_contents authentication gives '401 Access Denied Error'

I am trying to create a database in cpanel using the folowing comment
$result =file_get_contents("http://$cpanel_user:$cpanel_password#$cpanel_host:2082/frontend/$cpanel_skin/sql/adddb.html?db=$db_name")
echo $result;
this command gives me HTTP request failed! HTTP/1.1 401 Access Denied error. I have used the correct password and username for connecting. And i am able to create the database when i give this url(url in this format) in a browsers url field.
Can someone explain what seems to be the problem?
That is not the correct way to create databases using cPanel. I believe you are trying to replicate the form inside cPanel to create databases, which is not correct.
Also, you will not be able to create databases using your cPanel username and password. I think you should refer to this thread to resolve your issue.

Facebook "cross-domain receiver URL" application error

It needs Facebook facepile plugin(http://developers.facebook.com/docs/reference/plugins/facepile). I tried but I am getting this error
(The Facebook Connect cross-domain receiver URL (http://static.ak.fbcdn.net/connect/xd_proxy.php#?=&cb=f223d517566e616&origin=http%3A%2F%2Fpromolife.com.au%2Ff3e13728ba8ec8&relation=parent.parent&transport=postmessage) must have the application's Connect URL (http://www.testsite.com.au/) as a prefix. You can configure the Connect URL in the Application Settings Editor.)
Why do I get this error?
Your connect URL must be the same as the URL you are running the script on & the callback URL. When I say the same I also mean EXACTLY the same in the sense of whether you are using http://yoursite or http://www.yoursite. Double check your app settings to make sure for no typo's in the connect URL also.

Categories