Mewp / lightopenid

Automatically exported from code.google.com/p/lightopenid
MIT License
4 stars 12 forks source link

Example error #19

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,

I had difficulties with your example.php, because the openId provider that I 
was using as test (Hyves.nl) uses POST callbacks rather than GET. So your login 
example failed because it only looks at $_GET['openid_mode']. I fixed this, and 
I also merged the Google example into the regular example (might be more 
convenient for most people). You might not agree with the latter, however here 
is the code.

Thanks!
Niels

>---

try {
    $openid_mode = '';
    if (isset($_GET['openid_mode']) ){
        $openid_mode=$_GET['openid_mode'];
    } else if (isset($_POST['openid_mode'])) {
        $openid_mode=$_POST['openid_mode'];
    } 
    if($openid_mode=='' ) {
        if (isset($_POST['openid_identifier'])) {
            $openid = new LightOpenID;

            // Google only provider
            if (strpos($_POST['openid_identifier'],'google')!==FALSE || 
                strpos($_POST['openid_identifier'],'gmail')!==FALSE) {
                $openid->identity = 'https://www.google.com/accounts/o8/id';
            } else {
                $openid->identity = $_POST['openid_identifier'];
            }
            header('Location: ' . $openid->authUrl());
        }
?>
<form action="" method="post">
    OpenID: <input type="text" name="openid_identifier" /> <button>Submit</button>
</form>
<?php
    } elseif ($openid_mode == 'cancel'   ) {
        echo 'User has canceled authentication!';
    } else {
        $openid = new LightOpenID;
        echo 'User ' . ($openid->validate() ? $openid->identity . ' has ' : 'has not ') . 'logged in.';
    }
} catch(ErrorException $e) {
    echo $e->getMessage();
}

Original issue reported on code.google.com by nielsba...@gmail.com on 22 Nov 2010 at 12:47

GoogleCodeExporter commented 9 years ago
You've broken the support for google profiles while merging the examples (urls 
like http://google.com/profiles/login). Don't do things like guessing what a 
openid identifier might be -- it's wrong, and can easily cause problems. And 
even if it doesn't, it's confusing to the user, because it works differently on 
different websites. That's one of the reasons why google-example.php has a 
button.

That said, I'll push a commit soon, that fixes it.

Original comment by mewp...@gmail.com on 22 Nov 2010 at 11:43

GoogleCodeExporter commented 9 years ago
I have added $openid->mode that returns openid.mode either from $_GET or 
$_POST, depending on where it's avaiable.

Original comment by mewp...@gmail.com on 22 Nov 2010 at 3:29

GoogleCodeExporter commented 9 years ago
That's cool, thanx!

Original comment by nielsba...@gmail.com on 24 Nov 2010 at 11:02