I'm having problems with a small OpenID-library called LightOpenID . I can authenticate to almost all providers, but I don't know how to fetch the data from the provider. I only get Array(), even with print_r().
Asked
Active
Viewed 3,125 times
8
-
1We need more information... how about telling us exactly what you've tried (as in, copy and paste your code) and then tell us the results (as in, copy and paste). – Narcissus Jul 05 '10 at 12:21
-
Sorry, here is the code: http://pastebin.com/kS9S4WVk Everything works pretty well, but on line 39-41 I try to print the email of the current account. The result is "Array()". – Pwntus Jul 05 '10 at 12:54
-
Is error reporting / display errors on? Have you checked your PHP error log? – Narcissus Jul 05 '10 at 13:19
2 Answers
8
You need to call getAttributes()
after $openid->validate()
not before.
Remember:
Note that it does not guarantee that any of the required/optional parameters will be present

Pete
- 1,773
- 8
- 11
-
I've done like this now: http://pastebin.com/ULsLvhxp So to display the email, do I use $foo['email']? – Pwntus Jul 05 '10 at 13:56
-
It'll be `$foo['contact/email']` - as per the docs, the attributes are mapped to the AX format. – Pete Jul 05 '10 at 14:20
-
2Also, `$openid->required = array('contact/email');` needs to be called **before** `$openid->validate()` – Pete Jul 05 '10 at 14:27
-
http://pastebin.com/Xrhh7Ukb - Still not working, I'm pretty sure it should show some nickname or email. – Pwntus Jul 05 '10 at 14:40
-
You've got `$openid->validate();` twice. Also, as mentioned, there's no guarantee that the OP or user exchanges the information. – Pete Jul 05 '10 at 15:05
2
This is how I use it. This is the file openid.php in the folder lightopenid. In the class make the following additional functions -
class LightOpenID
{
public $returnUrl
, $required = array()
, $optional = array()
, $verify_peer = null
, $capath = null
, $cainfo = null;
// these are the variables which store the data about the user...
public function ret_fname() { return $this->data['openid_ext1_value_namePerson_first']; }
public function ret_lname() { return $this->data['openid_ext1_value_namePerson_last']; }
public function ret_email() { return $this->data['openid_ext1_value_contact_email']; }
public function ret_lang() { return $this->data['openid_ext1_value_pref_language']; }
}
Now make your file example login.php which is called when you want to authenticate. There might be several copies of this file for different authentication domains etc.
<?php
# Logging in with Google accounts requires setting special identity, so this example shows how to do it.
session_start();
require 'lightopenid/openid.php';
include_once('config.php'); // initial setting file
try {
$openid = new LightOpenID; // akshat - declared an object of class lightopenid.. this is listed in openid.php
if(!$openid->mode) {
if(isset($_GET['login'])) {
$openid->identity = 'https://www.google.com/accounts/o8/site-xrds?hd=YourDomain.in'; //this can be changed as you know...
$openid->required = array('namePerson/friendly', 'contact/email' , 'contact/country/home', 'namePerson/first', 'pref/language', 'namePerson/last'); // akshat - line added by me from after reading from the net....
header('Location: ' . $openid->authUrl());
}
?>
<script type="text/javascript" src="js/jquery-1.4.2.min.js" language="javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
document.form.submit();
});
</script>
<form name="form" action="?login" method="post"> </form>
<?php
} elseif($openid->mode == 'cancel') {
echo 'User has canceled authentication for Your Domain !';
} else { // FETCH USER INFO HERE
$fname = $openid->ret_fname(); // fetching user first name...
$lname = $openid->ret_lname(); // fetching user last name...
$email = $openid->ret_email(); // fetching user email...
$lang = $openid->ret_lang(); // fetching user language...
session_start();
// use it as required. I set them in session !
$_SESSION['admin']['emailID'] = $email; //put email id in session.
$_SESSION['admin']['fname'] = $fname; //put first name also in session.
$_SESSION['admin']['lname'] = $lname; //put last name also in session.
$rurl = $_SESSION['redirect']; // you can ignore this. Go to your own page now...
header("Location:$rurl"); // Go back to the calling application !
}
} catch(ErrorException $e) {
echo $e->getMessage();
}
?>

Floccinaucinihilipilification.
- 512
- 6
- 13