src/snac/server/database/DBUser.php
/**
     * Authenticate User by API Key
     *
     * This method is the heart of the API key authentication protocol.  Given
     * an API key ($key), this method grabs the label off of the key, then tries
     * to find the API key that matches that label and can be correctly validated
     * using the full key (i.e., the encryption scheme built into PHP can verify
     * that the stored encrypted full-key given by the label matches the key).
     *
     * If it can be found, it then reads the user object out of the database for
     * the user and returns it.
     *
     * @param string $key The API key to authenticate
     * @return \snac\data\User $user The user for the authenticated key
     * @throws \snac\exceptions\SNACUserException
     */
Authenticate User by API Key
This method is the heart of the API key authentication protocol.  Given
an API key ($key), this method grabs the label off of the key, then tries
to find the API key that matches that label and can be correctly validated
using the full key .

If it can be found, it then reads the user object out of the database for
the user and returns it.


Authenticate User by API Key This method is the heart of the API key authentication protocol . Given an API key ( $key ) this method grabs the label off of the key then tries to find the API key that matches that label and can be correctly validated using the full key . If it can be found it then reads the user object out of the database for the user and returns it .
public function authenticateUserByAPIKey($key) {
        $label = substr($key, 0, 8);
        $keyData = $this->sql->selectAPIKeyByKey($key, $label);
        if ($keyData == null)
            throw new \snac\exceptions\SNACUserException("API Key is not authorized", 403);
        if (strtotime($keyData["expires"]) - time() < 0)
            throw new \snac\exceptions\SNACUserException("API Key has expired", 403);
        $userid = $keyData["uid"];
        $tmpUser = new \snac\data\User();
        $tmpUser->setUserID($userid);
        $user = $this->readUser($tmpUser);
        if ($user === false)
            throw new \snac\exceptions\SNACUserException("API Key is not authorized for a user", 403);
        return $user;
    }
public function authenticateUserByAPIKey ( $ key ) { $ label = substr ( $ key , 0 , 8 ) ; $ keyData = $ this -> sql -> selectAPIKeyByKey ( $ key , $ label ) ; if ( $ keyData == null ) throw new \ snac \ exceptions \ SNACUserException ( " API Key is not authorized " , 403 ) ; if ( strtotime ( $ keyData [ " expires " ] ) - time ( ) < 0 ) throw new \ snac \ exceptions \ SNACUserException ( " API Key has expired " , 403 ) ; $ userid = $ keyData [ " uid " ] ; $ tmpUser = new \ snac \ data \ User ( ) ; $ tmpUser -> setUserID ( $ userid ) ; $ user = $ this -> readUser ( $ tmpUser ) ; if ( $ user === false ) throw new \ snac \ exceptions \ SNACUserException ( " API Key is not authorized for a user " , 403 ) ; return $ user ; }
Authenticate User by API Key
 This method is the heart of the API key authentication protocol.
Authenticate User by API Key This method is the heart of the API key authentication protocol .