I am new to the OpenID logic. I am using the OpenID component for CakePHP by Cakebaker, with the PHP OpenID library by JanRain.
It's all working quite well, but I could not find an exhaustive way to retrieve user informations depending on provider and method (sreg vs. ax). So this is what I came up with:
if ($axResponse) {
if (is_array($a = $axResponse->get('http://axschema.org/contact/email'))) {
$user_record['email'] = $a[0];
if (is_array($b = $axResponse->get('http://axschema.org/namePerson'))) {
$user_record['nickname'] = $b[0];
}
} else if (is_array($a = $axResponse->get('http://schema.openid.net/contact/email'))) {
$user_record['email'] = $a[0];
if (is_array($b = $axResponse->get('http://schema.openid.net/namePerson'))) {
$user_record['nickname'] = $b[0];
}
}
} else if ($sreg) {
if (isset($sreg['email'])) {
$user_record['email'] = $sreg['email'];
}
if (isset($sreg['nickname'])) {
$user_record['nickname'] = $sreg['nickname'];
}
}
Although I tested it successfully with Google, Yahoo! and AOL's OpenID, I'm sure I would run into trouble with other / smaller providers. Is there a better and nicer way to achieve the same result? This seems particularly flawed if I try to fetch other optional fields...
Please keep in mind that OpenID is a standard for user authentication, not for authorization for data access. You can, naturally, get certain user info using OpenID, but it's not the protocol's primary intent. OAuth is the standard for authorization and you might want to start with that, if fetching user data is what you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With