PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Attaching Information Cards to existing accounts

It is possible to add support for information cards to an existing authentication system by storing the private personal identifier (PPI) to a previously traditionally-authenticated account and including at least the http://schemas.xmlsoap.org/ws/2005/05/identity/claims/privatepersonalidentifier claim as part of the requiredClaims of the request. If this claim is requested then the Zend_InfoCard_Claims object will provide a unique identifier for the specific card that was submitted by calling the getCardID() method.

An example of how to attach an information card to an existing traditional-authentication account is shown below:

<?php
// ...
public function submitinfocardAction()
{
    if (!isset(
$_REQUEST['xmlToken'])) {
        throw new 
ZBlog_Exception('Expected an encrypted token ' .
                                  
'but was not provided');
    }

    
$infoCard = new Zend_InfoCard();
    
$infoCard->addCertificatePair(SSL_CERTIFICATE_PRIVATE,
                                  
SSL_CERTIFICATE_PUB);

    try {
        
$claims $infoCard->process($request['xmlToken']);
    } catch(
Zend_InfoCard_Exception $e) {
        
// TODO Error processing your request
        
throw $e;
    }

    if (
$claims->isValid()) {
        
$db ZBlog_Data::getAdapter();

        
$ppi $db->quote($claims->getCardID());
        
$fullname $db->quote("{$claims->givenname} {$claims->surname}");

        
$query "UPDATE blogusers
                     SET ppi = 
$ppi,
                         real_name = 
$fullname
                   WHERE username='administrator'"
;

        try {
            
$db->query($query);
        } catch(
Exception $e) {
            
// TODO Failed to store in DB
        
}

        
$this->view->render();
        return;
    } else {
        throw new
            
ZBlog_Exception("Infomation card failed security checks");
    }
}

Zend Framework