Skip to content

Commit

Permalink
Merge pull request #1 from OneID/doc_1
Browse files Browse the repository at this point in the history
Doc 1 is ready for integration
  • Loading branch information
jandrieu committed Sep 20, 2012
2 parents 5ef1d2a + e4b19d4 commit a71795a
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 54 deletions.
1 change: 1 addition & 0 deletions examples/oneid_demo/api_key-stage.json
@@ -0,0 +1 @@
{"API_KEY": "S7nB18z6DrM6RypXFsTxrg==", "API_ID": "052b0422-f23e-4e64-9e72-d6d3a45635b5"}
11 changes: 8 additions & 3 deletions examples/oneid_demo/index.php
Expand Up @@ -8,15 +8,20 @@
<a href="provision.php">Go here to try out one-click provision</a>

<H3>Login</H3>
Click on this button to login: <?php echo OneID_Button("https://localhost:444/demo/login.php"); ?>
Click on this button to login: <?php echo OneID_Button("login.php"); ?>


<H3>Form Fill</H3>
Click on <a href="form.php">this link</a> to try out the form fill demo.

You should already have a OneID to try this out.
<p>NONCE:
<?php echo _dump_call_OneID("make_nonce");?></p>
<p>SERVERS: <?php echo $oneid_servers ?>


<script type="application/javascript">

localStorage['logLevel'] = 1;



</script>
12 changes: 0 additions & 12 deletions examples/oneid_demo/login.php

This file was deleted.

83 changes: 62 additions & 21 deletions examples/oneid_demo/oneid.php
@@ -1,24 +1,29 @@
<?php

$oneid_server = "https://keychain.oneid.com";
// core service and javascript resources
// set your servers to swap from production to alternative deployments

//$servers = ""; // use production
$oneid_servers = "-stage"; // use stage

// Set your values here
//$oneid_api_id = "00010001-a6ca-4ece-9d74-0f97f63fac4d";
//$oneid_api_key = "xxx";

$oneid_api_key = "w1AOy2TUwGkalcFUxyyeAA==";
$oneid_api_id = "f57956b0-cf70-4497-8b88-d3660412f5ff";
$oneid_server = "https://keychain".$oneid_servers.".oneid.com";
$oneid_script = '<script src="https://api'.$oneid_servers.'.oneid.com/js/includeexternal.js" type="text/javascript"></script>';

// Set your values here
$oneid_referral_code = "yyy";
$oneid_script = '<script src="https://api.oneid.com/js/includeexternal.js" type="text/javascript"></script>';

// Load key file
$key = json_decode(file_get_contents("api_key" . $oneid_servers . ".json"),true);
$oneid_api_id = $key['API_ID'];
$oneid_api_key = $key['API_KEY'];

function _call_OneID($method, $post = null) {
global $oneid_server, $oneid_api_id, $oneid_api_key;

//$scope = "/repo";
$scope = "";
$ch = curl_init($oneid_server . $scope. "/" . $method);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD, $oneid_api_id . ":" . $oneid_api_key);

Expand All @@ -32,6 +37,27 @@ function _call_OneID($method, $post = null) {
return json_decode($json, true);
}

function _dump_call_OneID($method, $post = null) {
global $oneid_server, $oneid_api_id, $oneid_api_key;

//$scope = "/repo";
$scope = "";
$ch = curl_init($oneid_server . $scope. "/" . $method);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD, $oneid_api_id . ":" . $oneid_api_key);

if ($post !== null) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
$json = curl_exec($ch);
curl_close($ch);

return $json;
}


function OneID_SetCredentials($id, $key) {
global $oneid_api_id, $oneid_api_key;

Expand Down Expand Up @@ -69,37 +95,52 @@ function OneID_MakeNonce() {
}

function OneID_Response() {
$resp = file_get_contents('php://input');

$validate = _call_OneID("validate", $resp);

if ($validate["errorcode"] != 0) {
return FALSE;
#$response = json_decode(file_get_contents('php://input'),true); // get post data as a string
$response = file_get_contents('php://input'); // get post data as a string

$validate = _call_OneID("validate", $response);
if (!OneID_IsSuccess($validate)) {
$validate['failed']="failed";
return $validate;
}

$arr = json_decode($resp, true);

$arr = json_decode($response, true);
$arr['errorcode'] = $validate['errorcode'];
$arr['error'] = $validate['error'];

return $arr;
}

function OneID_Button($callback) {
return '<img class="oneidlogin" id="oneidlogin" data-challenge=\'{"nonce":"' . OneID_MakeNonce() . '","attr":"personal_info[email]","CALLBACK":"'. $callback . '"}\' src="https://api.oneid.com/images/oneid_signin.png" onclick="OneId.login()">';
return '<img class="oneidlogin" id="oneidlogin" data-challenge=\'{"nonce":"' . OneID_MakeNonce() . '","attr":"personal_info[email]","callback":"'. $callback . '"}\' src="https://api'.$oneid_servers.'.oneid.com/images/oneid_signin.png" onclick="OneId.login()">';
}

function OneID_FormFill($attrs) {
return '<img class="oneidlogin" id="oneidlogin" src="https://api.oneid.com/images/btn_id_signin.gif" onclick="OneId.login()">';
return '<img class="oneidlogin" id="oneidlogin" src="https://api'.$oneid_servers.'.oneid.com/api/images/btn_id_signin.gif" onclick="OneId.login()">';
}

function OneID_Redirect($page) {
return ('{"error":"success","url":"'. $page .'"}');
function OneID_Redirect($page,$response) {
return ('{"error":"'
. $response['error']
. '","errorcode":"'
. $response['errorcode']
. '","url":"'
. $page
. '","response":'
. json_encode($response)
. '}');
}

function OneID_Provision($emailAddress, $attrs) {
global $oneid_referral_code;

return ('<img id="getAOneIdButton" class="oneidlogin"
ref="' . $oneid_referral_code . '"
src="https://api.oneid.com/images/btn_id_signin.png"
src="https://api'.$servers.'.oneid.com/images/btn_id_signin.png"
data-userattrs = \'' . json_encode($attrs) . '\'
onclick="OneId.createOneId()" >');
}

function OneID_IsSuccess($response) {
return !$response['errorcode'];
}
28 changes: 28 additions & 0 deletions examples/oneid_demo/verify.php
@@ -0,0 +1,28 @@
<?php
require("oneid.php");

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

session_start();

if(OneID_IsSuccess($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
unset($_SESSION['OneID']);
unset($_SESSION['email']);
$_SESSION=array_values($_SESSION);
}

// return the redirect to the next page

echo OneID_Redirect('account.php',$response);

// OneID_redirect will send the browser to the next page and pass any errorcodes from authentication and verification back to the OneID client.

?>
81 changes: 63 additions & 18 deletions oneid.php
@@ -1,20 +1,29 @@
<?php

$oneid_server = "https://keychain.oneid.com";
// core service and javascript resources
// set your servers to swap from production to alternative deployments

//$servers = ""; // use production
$oneid_servers = "-stage"; // use stage


$oneid_server = "https://keychain".$oneid_servers.".oneid.com";
$oneid_script = '<script src="https://api'.$oneid_servers.'.oneid.com/js/includeexternal.js" type="text/javascript"></script>';

// Set your values here
$oneid_api_id = "00010001-a6ca-4ece-9d74-0f97f63fac4d";
$oneid_api_key = "xxx";
$oneid_referral_code = "yyy";
$oneid_script = '<script src="https://api.oneid.com/js/includeexternal.js" type="text/javascript"></script>';

// Load key file
$key = json_decode(file_get_contents("api_key" . $oneid_servers . ".json"),true);
$oneid_api_id = $key['API_ID'];
$oneid_api_key = $key['API_KEY'];

function _call_OneID($method, $post = null) {
global $oneid_server, $oneid_api_id, $oneid_api_key;

//$scope = "/repo";
$scope = "";
$ch = curl_init($oneid_server . $scope. "/" . $method);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD, $oneid_api_id . ":" . $oneid_api_key);

Expand All @@ -28,6 +37,27 @@ function _call_OneID($method, $post = null) {
return json_decode($json, true);
}

function _dump_call_OneID($method, $post = null) {
global $oneid_server, $oneid_api_id, $oneid_api_key;

//$scope = "/repo";
$scope = "";
$ch = curl_init($oneid_server . $scope. "/" . $method);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD, $oneid_api_id . ":" . $oneid_api_key);

if ($post !== null) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
$json = curl_exec($ch);
curl_close($ch);

return $json;
}


function OneID_SetCredentials($id, $key) {
global $oneid_api_id, $oneid_api_key;

Expand Down Expand Up @@ -65,37 +95,52 @@ function OneID_MakeNonce() {
}

function OneID_Response() {
$resp = file_get_contents('php://input');

$validate = _call_OneID("validate", $resp);

if ($validate["errorcode"] != 0) {
return FALSE;
#$response = json_decode(file_get_contents('php://input'),true); // get post data as a string
$response = file_get_contents('php://input'); // get post data as a string

$validate = _call_OneID("validate", $response);
if (!OneID_IsSuccess($validate)) {
$validate['failed']="failed";
return $validate;
}

$arr = json_decode($resp, true);

$arr = json_decode($response, true);
$arr['errorcode'] = $validate['errorcode'];
$arr['error'] = $validate['error'];

return $arr;
}

function OneID_Button($callback) {
return '<img class="oneidlogin" id="oneidlogin" data-challenge=\'{"nonce":"' . OneID_MakeNonce() . '","attr":"personal_info[email]","CALLBACK":"'. $callback . '"}\' src="https://api.oneid.com/images/oneid_signin.png" onclick="OneId.login()">';
return '<img class="oneidlogin" id="oneidlogin" data-challenge=\'{"nonce":"' . OneID_MakeNonce() . '","attr":"personal_info[email]","callback":"'. $callback . '"}\' src="https://api'.$oneid_servers.'.oneid.com/images/oneid_signin.png" onclick="OneId.login()">';
}

function OneID_FormFill($attrs) {
return '<img class="oneidlogin" id="oneidlogin" src="https://api.oneid.com/api/images/btn_id_signin.gif" onclick="OneId.login()">';
return '<img class="oneidlogin" id="oneidlogin" src="https://api'.$oneid_servers.'.oneid.com/api/images/btn_id_signin.gif" onclick="OneId.login()">';
}

function OneID_Redirect($page) {
return ('{"error":"success","url":"'. $page .'"}');
function OneID_Redirect($page,$response) {
return ('{"error":"'
. $response['error']
. '","errorcode":"'
. $response['errorcode']
. '","url":"'
. $page
. '","response":'
. json_encode($response)
. '}');
}

function OneID_Provision($emailAddress, $attrs) {
global $oneid_referral_code;

return ('<img id="getAOneIdButton" class="oneidlogin"
ref="' . $oneid_referral_code . '"
src="https://api.oneid.com/images/btn_id_signin.png"
src="https://api'.$servers.'.oneid.com/images/btn_id_signin.png"
data-userattrs = \'' . json_encode($attrs) . '\'
onclick="OneId.createOneId()" >');
}

function OneID_IsSuccess($response) {
return !$response['errorcode'];
}

0 comments on commit a71795a

Please sign in to comment.