Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
102 lines (70 sloc) 3.31 KB


Read the doc for the PHP class in .

This tutorial uses a small PHP library that implements the relevant calls to the OneID web services.

The demo uses a OneID Helper Service. To use the Helper Service you will also need to download an API Key from into the same directory as the demo. Name the api key file api_key.json. By downloading the API Key you agree to the OneID Developer Agreement. The API Key gives you access to OneID Helper Services,

The OneID Helper Service is not required, but is used in the example code. Without the Helpers Services, you will need to validate credentials and create nonces on your own.

If you have any questions, contact


PHP5 is required.

apt-get install php5-cli php5-curl

Running the sample code

git clone
cd oneid-php-sdk/examples/oneid_demo/
vi api_key.json   ### Copy&Paste the API key from register

php -S localhost:8000

Now point your Browser to http://localhost:8000

Replace "localhost" with your server's name as needed.



Implementing OneID sign-in is a three step process, one for each page on your server. On the page where you want the sign-in button, you include a script tag and place the login button. The PHP library has helper variables and functions to make this simple:

<?php require("oneid.php"); 
          $oneid = new OneID();
          echo $oneid->oneid_script; // This inserts the script tag 

    // This inserts the sign-in button
    <div id="login-button"/>
    <script type="text/javascript">
            buttons: {
                "signin #login-button": [{
                    challenge: {
                        "callback": "/validate.php"
                        "attr": "email name address"


validate.php is called by the OneID client during the authentication protocol. The code is:

$oneid = new OneID();

$response = $oneid->response(); 
// This function handles validation of
// the response from OneID and returns an 
// array of attributes for the user.


if($oneid->success($response)) {
        // here you do what you need to link the OneID with the current user.
        $_SESSION['email'] = $response['attr']['personal_info']['email'];
        $_SESSION['OneID'] = $response['uid'];
else { 
// if it fails, clear whatever link may have been set previously

echo $oneid->redirect('account.php', $response);

// $oneid->redirect will return JSON that will send the browser to the specified page and pass any errorcodes from authentication and verification back to the OneID client.



account.php creates the destination URL where you want the client’s browser to land after signing in successfully. The code is:

<?php session_start(); ?>
Welcome, <?php echo $_SESSION['email']; ?>  your OneID is <?php echo $_SESSION['OneID'];
Something went wrong with that request. Please try again.