0

I've been trying to implement openID authentication as a consumer in a project I'm developing, and I haven't yet managed to make even the examples work as I want.

Even though the example consumer works perfectly for yahoo openid authentication, it fails in the try_auth.php page with a 501 HTTP error when trying to use google openID.

Here's the code for try_auth.php (the page that handles the call to the actual openID provider):

<?php
error_reporting(E_ALL);
ini_set('display_errors','On');
require_once "common.php";
session_start();

function getOpenIDURL() {
    // Render a default page if we got a submission without an openid
    // value.
    if (empty($_GET['openid_identifier'])) {
        $error = "Expected an OpenID URL.";
        include 'index.php';
        exit(0);
    }

    return $_GET['openid_identifier'];
}

function run() {
    $openid = getOpenIDURL();
    $consumer = getConsumer();

    // Begin the OpenID authentication process.
    $auth_request = $consumer->begin($openid);

    // No auth request means we can't begin OpenID.
    if (!$auth_request) {
        displayError("Authentication error; not a valid OpenID.");
    }

    $sreg_request = Auth_OpenID_SRegRequest::build(
                                     // Required
                                     array('nickname'),
                                     // Optional
                                     array('fullname', 'email'));

    if ($sreg_request) {
        $auth_request->addExtension($sreg_request);
    }

    $policy_uris = null;
    if (isset($_GET['policies'])) {
        $policy_uris = $_GET['policies'];
    }

    $pape_request = new Auth_OpenID_PAPE_Request($policy_uris);
    if ($pape_request) {
        $auth_request->addExtension($pape_request);
    }

    // Redirect the user to the OpenID server for authentication.
    // Store the token for this authentication so we can verify the
    // response.

    // For OpenID 1, send a redirect.  For OpenID 2, use a Javascript
    // form to send a POST request to the server.
    if ($auth_request->shouldSendRedirect()) {
        $redirect_url = $auth_request->redirectURL(getTrustRoot(),
                                                   getReturnTo());

        // If the redirect URL can't be built, display an error
        // message.
        if (Auth_OpenID::isFailure($redirect_url)) {
            displayError("Could not redirect to server: " . $redirect_url->message);
        } else {
            // Send redirect.
            header("Location: ".$redirect_url);
        }
    } else {
        // Generate form markup and render it.
        $form_id = 'openid_message';
        $form_html = $auth_request->htmlMarkup(getTrustRoot(), getReturnTo(),
                                               false, array('id' => $form_id));

        // Display an error if the form markup couldn't be generated;
        // otherwise, render the HTML.
        if (Auth_OpenID::isFailure($form_html)) {
            displayError("Could not redirect to server: " . $form_html->message);
        } else {
            print $form_html;
        }
    }
}

run();

?>

Another think I noticed is that on my windows dev box (Apache 2.2.6 standalone, not XAMPP, PHP 5.3.8) everything runs smoothly, both yahoo and Google perform openID authentication without any issues.

Anyone have an idea what might be wrong?

Thanks in advance.

hakre
  • 193,403
  • 52
  • 435
  • 836
Yiangos
  • 267
  • 2
  • 10
  • it's the example consumer code that ships with janrain openid. I haven't changed a single line of code from in there. I'll be posting the file as soon as I have access to my main dev machine... – Yiangos Apr 08 '12 at 16:03
  • add `error_reporting(E_ALL);` and `ini_set('display_errors','On');` to your code and extract the exact PHP error – Baba Apr 08 '12 at 16:05
  • I doubt this is a PHP error. PHP errors result in a 500 HTTP error from the Apache server. However, I'm getting a 501 HTTP Error - i.e. method not implemented. What's really odd, is that the same setup works fine if I use Yahoo OpenID. – Yiangos Apr 08 '12 at 16:23
  • Edited the initial post to include source code (including the error reporting and error display directives). Still getting 501 error when I try google open ID. I think it has something to do with the server, but I don't know what. – Yiangos Apr 08 '12 at 21:04

1 Answers1

0

After some trial and error, I came to the conclusion that the 501 error occurs due to the Google openID url being passed to the page either as querystring (for form method "get") either as postdata (for form method "post"). In particular, the url I was using is

https://www.google.com/accounts/o8/id

the last part (the "id") is triggering the 501 error. If I use

https://www.google.com/accounts/o8/id/

the error is not triggered. Well, since the two are equivalent urls, I'll be using the second one. I'm still curious as to why this was happening though.

Yiangos
  • 267
  • 2
  • 10