ekurowski
07-23-2009, 06:32 PM
just to start out on the correct note. I don't know that much about how the DekiWiki is written or configures. Actually my area of expertiese is not in the open source environment.
my problem is that we have a community site that we want to use as the authentication site and allow users to pass seamlessly to DekiWiki with out having to login in. I have read all of the pages I could find out there and have made an attempt to get a solution that works. I was able to get the authtoken from the DekiWiki server, but I could not get to a page on the DekiWiki and be logged in. Here is my code, with a few changes. Can any body help me?
<?php
// Wiki authentication parameters
// <-- Put your server address here ("http://" part is needed)
$apihost = 'http://deki.wiki.org';
$apipath = '@api/deki/users/authenticate';
$authprov = '1';
$apikey = '1234567890ABCDEFGhijklmnop';
$authuser = 'genericuser'; // <-- Put the required password here
$authpwd = '';
// Initialize cURL instance (requires php_curl module in php.ini)
$httpclient = curl_init();
// Configure the target URL and HTTP method for the request
$authurl = $apihost.'/'.$apipath.'?authprovider='.$authprov.'&APIKEY='.$apikey;
//curl_setopt($httpclient, CURLOPT_POST, TRUE); this generated an error
// other web pages suggested trying it with out this statement. It seemed to work.
curl_setopt($httpclient, CURLOPT_URL, $authurl);
// Setup request to pass a HTTP basic auth header
curl_setopt($httpclient, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($httpclient, CURLOPT_USERPWD, $authuser.':'.$pwd);
// Set user agent header and allow redirects in case url is missing ending "/"
curl_setopt($httpclient, CURLOPT_USERAGENT,"ASM Wiki Authenticator/1.0");
curl_setopt($httpclient, CURLOPT_FOLLOWLOCATION,1);
// Set connection and request timeouts (seconds)
curl_setopt($httpclient, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($httpclient, CURLOPT_TIMEOUT, 15);
// Request cURL to fail on error
curl_setopt($httpclient, CURLOPT_FAILONERROR, TRUE);
// Request HTTP response be returned as a string
curl_setopt($httpclient, CURLOPT_RETURNTRANSFER, TRUE);
// Setup cURL error logging to a file for debugging (disable for production)
$errorfile = fopen("/var/www/CommunityDZ/deki_auth_error.txt", "w");
curl_setopt($httpclient, CURLOPT_STDERR, $errorfile);
// Disable extra header stuff (not needed)
curl_setopt($httpclient, CURLOPT_HEADER, 0);
// Execute the auth request and get the HTTP result code
$authresponse = curl_exec($httpclient);
$httpcode = curl_getinfo($httpclient, CURLINFO_HTTP_CODE);
// Decide what to do based on the HTTP response code
if ($httpcode != 200) {
print 'Wiki authentication failed with HTTP code ' . $httpcode . ";
print '<br>curl error: '.curl_error($httpclient);
} else {
print 'Wiki authentication suceeded!</br>';
print 'Auth cookie value is "'.substr($authresponse,1,80);
// Note: substr guards against potential string overflow
}
// Dispose of cURL instance
curl_close($httpclient);
// Close debugging file (disable for production)
fclose($errorfile);
?>
my problem is that we have a community site that we want to use as the authentication site and allow users to pass seamlessly to DekiWiki with out having to login in. I have read all of the pages I could find out there and have made an attempt to get a solution that works. I was able to get the authtoken from the DekiWiki server, but I could not get to a page on the DekiWiki and be logged in. Here is my code, with a few changes. Can any body help me?
<?php
// Wiki authentication parameters
// <-- Put your server address here ("http://" part is needed)
$apihost = 'http://deki.wiki.org';
$apipath = '@api/deki/users/authenticate';
$authprov = '1';
$apikey = '1234567890ABCDEFGhijklmnop';
$authuser = 'genericuser'; // <-- Put the required password here
$authpwd = '';
// Initialize cURL instance (requires php_curl module in php.ini)
$httpclient = curl_init();
// Configure the target URL and HTTP method for the request
$authurl = $apihost.'/'.$apipath.'?authprovider='.$authprov.'&APIKEY='.$apikey;
//curl_setopt($httpclient, CURLOPT_POST, TRUE); this generated an error
// other web pages suggested trying it with out this statement. It seemed to work.
curl_setopt($httpclient, CURLOPT_URL, $authurl);
// Setup request to pass a HTTP basic auth header
curl_setopt($httpclient, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($httpclient, CURLOPT_USERPWD, $authuser.':'.$pwd);
// Set user agent header and allow redirects in case url is missing ending "/"
curl_setopt($httpclient, CURLOPT_USERAGENT,"ASM Wiki Authenticator/1.0");
curl_setopt($httpclient, CURLOPT_FOLLOWLOCATION,1);
// Set connection and request timeouts (seconds)
curl_setopt($httpclient, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($httpclient, CURLOPT_TIMEOUT, 15);
// Request cURL to fail on error
curl_setopt($httpclient, CURLOPT_FAILONERROR, TRUE);
// Request HTTP response be returned as a string
curl_setopt($httpclient, CURLOPT_RETURNTRANSFER, TRUE);
// Setup cURL error logging to a file for debugging (disable for production)
$errorfile = fopen("/var/www/CommunityDZ/deki_auth_error.txt", "w");
curl_setopt($httpclient, CURLOPT_STDERR, $errorfile);
// Disable extra header stuff (not needed)
curl_setopt($httpclient, CURLOPT_HEADER, 0);
// Execute the auth request and get the HTTP result code
$authresponse = curl_exec($httpclient);
$httpcode = curl_getinfo($httpclient, CURLINFO_HTTP_CODE);
// Decide what to do based on the HTTP response code
if ($httpcode != 200) {
print 'Wiki authentication failed with HTTP code ' . $httpcode . ";
print '<br>curl error: '.curl_error($httpclient);
} else {
print 'Wiki authentication suceeded!</br>';
print 'Auth cookie value is "'.substr($authresponse,1,80);
// Note: substr guards against potential string overflow
}
// Dispose of cURL instance
curl_close($httpclient);
// Close debugging file (disable for production)
fclose($errorfile);
?>