Skip to content

Instantly share code, notes, and snippets.

@Pablissimo
Last active December 27, 2015 03:49
Show Gist options
  • Save Pablissimo/7262415 to your computer and use it in GitHub Desktop.
Save Pablissimo/7262415 to your computer and use it in GitHub Desktop.
require_once('/var/www/resources/MiiCard/miiCard.Consumers/miiCard.Consumers.php');
if (session_id() == "")
{
session_start();
}
$miiCardObj = new Consumers\MiiCard(MIICARD_CONSUMER_KEY, MIICARD_CONSUMER_SECRET, null, null, null, MIICARD_FORCE_CLAIMS, MIICARD_SIGNUP_MODE);
if ($miiCardObj->isAuthorisationCallback())
{
$miiCardObj->handleAuthorisationCallback();
if ($miiCardObj->isAuthorisationSuccess())
{
$miiCardClaimsService = new Consumers\MiiCardOAuthClaimsService(MIICARD_CONSUMER_KEY, MIICARD_CONSUMER_SECRET, $miiCardObj->getAccessToken(), $miiCardObj->getAccessTokenSecret());
$snapshots = $miiCardClaimsService->getIdentitySnapshotDetails()->getData();
if (count($snapshots) > 0) {
// Snapshot details returned date-descending order - so the first is most
// recent
$latestSnapshotDetails = $snapshots[0];
// Record the snapshot ID each time you get one - that's your 'proof token'
// for auditing and compliance
$snapshotId = $latestSnapshot->getDetails()->getSnapshotId();
// Using the latest snapshot ID from the above, pull in the actual snapshotted data
$latestSnapshot = $miiCardClaimsService->getIdentitySnapshot($snapshotId)->getData();
// This is a point-in-time view of the miiCard member's shared data
$userProfile = $latestSnapshot->getSnapshot();
// This'll necessarily be true because you can't go through the transactional
// flow without it being so, but for future robustness check anyway
$identityAssured = $userProfile->getIdentityAssured();
// Use this to identify the miiCard member again in the future, in case you
// want to do 'login with miiCard' functionality
$username = $userProfile->getUsername();
// var_dump($userProfile);
var_dump($latestSnapshot);
}
else {
// Shouldn't be possible
}
}
else
{
header('Location: ' . BASE_URL . HASH . '?status=fail&header=Error verifying ID.&message=MiiCard authorization failed.');
exit(0);
}
}else{
$miiCardObj->beginAuthorisation();
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment