PHP LightOpenID client library
Features include:
- Composer support including autoloader
- Build URL to provider Openid login form
- Request fields (User information, e.g. the email address)
- Handle Openid provider login response
- Pass GET and POST values from outside (ability to use with Symfony2 or similar)
- Get the Openid ID and requested fields
Note: This is mirror of the official https://gitorious.org/lightopenid/lightopenid repo
Add the following lines to your composer.json configuration.
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/paza/LightOpenID"
}
],
"require": {
"paza/lightopenid": "*"
}
}git clone git@github.com:paza/LightOpenID.gitSet up Openid
$domain = 'www.mysite.com'; // Your domain
// Load LightOpenID
$openid = new Paza\OpenID\LightOpenID($domain);
// (required) Return URL
$openid->setReturnUrl('/relative/path/to/domain');
// (required) Set OpenID identity
$openid->setIdentity('https://www.google.com/accounts/o8/id');/**
* Available fields are
* 'namePerson/friendly'
* 'contact/email'
* 'namePerson'
* 'birthDate'
* 'person/gender'
* 'contact/postalCode/home'
* 'contact/country/home'
* 'pref/language'
* 'pref/timezone'
*/
// (optional) Set required fields
$openid->setRequired(array('contact/email'));
// (optional) Set optional fields
$openid->setOptional(array('namePerson', 'namePerson/friendly'));
// Get OpenID Auth URL
$authUrl = $openid->authUrl();// (required) Set GET or POST data retrieved from the Openid provider
$openid->setData($_GET);
// (required) Check if it is in the response state (response received from the OpenID provider)
if (!$openid->isResponseState()) {
// The response set is not a correct Openid response
}
// (required) Check if the user has cancelled the OpenID Auth
if ($openid->checkUserCancelled()) {
// The user cancelled the request
}
// (required) Validate the response
if ($openid->validate()) {
// Logged in
// (required) Get the unique user ID
$id = $openid->getClaimedId();
// (optional) Get User attributes
$attributes = $openid->getAttributes();
echo
} else {
// Not logged in
}$openid = new Paza\OpenID\LightOpenID('www.mysite.com');
$authUrl = $openid
->setReturnUrl('/relative/path/to/domain')
->setIdentity('https://www.google.com/accounts/o8/id')
->setRequired(array('contact/email'))
->setOptional(array('namePerson', 'namePerson/friendly'))
->authUrl();