Skip to content

paza/LightOpenID

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

86 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LightOpenID

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

Installation

Using composer

Add the following lines to your composer.json configuration.

{
    "repositories": [
        {
            "type": "vcs",
            "url":  "https://github.com/paza/LightOpenID"
        }
    ],
    "require": {
        "paza/lightopenid": "*"
    }
}

Without composer

git clone [email protected]:paza/LightOpenID.git

Usage

Set 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');

Get Openid URL (URL to login window of Openid provider)

/**
 * 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();

Handle Openid Response

// (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
}

Short form

$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();

About

Clone of a PHP 5 library for easy OpenID authentication. Authored by [email protected]

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages

  • PHP 100.0%