Source for file Auth.php

Documentation is available at Auth.php

  1. <?
  2.  
  3. /** Authentication methods.
  4.  *
  5.  * @package    php-lastfm-api
  6.  * @author  Felix Bruns <felixbruns@web.de>
  7.  * @version    1.0
  8.  */
  9. class Auth {
  10.     /** Returns a last.fm API signature for the given request parameters.
  11.      *
  12.      * @param    array    $params        Request parameters.
  13.      * @param    string    $apiSecret    Last.fm API secret.
  14.      * @return    string                Last.fm API signature.
  15.      *
  16.      * @static
  17.      * @access    public
  18.      */
  19.     public static function getApiSignature(array $params$apiSecret){
  20.         ksort($params);
  21.  
  22.         $string '';
  23.  
  24.         foreach($params as $name => $value){
  25.             $string .= $name $value;
  26.         }
  27.  
  28.         $string .= $apiSecret;
  29.  
  30.         return md5($string);
  31.     }
  32.  
  33.     /** Create a web service session for a user. Used for authenticating a user when the password can be inputted by the user. Only suitable for standalone mobile devices. See the authentication how-to for more.
  34.      *
  35.      * @param    string    $username    The last.fm username. (Required)
  36.      * @param    string    $password    The last.fm password. (Required)
  37.      * @return    Session                A Session object.
  38.      *
  39.      * @static
  40.      * @access    public
  41.      * @throws    Error
  42.      */
  43.     public static function getMobileSession($username$password){
  44.         $xml CallerFactory::getDefaultCaller()->signedCall('auth.getMobileSession'array(
  45.             'username'  => $username,
  46.             'authToken' => md5($username md5($password))
  47.         ));
  48.  
  49.         return Session::fromSimpleXMLElement($xml);
  50.     }
  51.  
  52.     /** Returns a session using an authorized token.
  53.      *
  54.      * @param    string    $token    A 32-character ASCII hexadecimal MD5 hash returned by step 1 of the authentication process (following the granting of permissions to the application by the user). (Required)
  55.      * @return    Session            A Session object.
  56.      *
  57.      * @static
  58.      * @access    public
  59.      * @throws    Error
  60.      */
  61.     public static function getSession($token){
  62.         $xml CallerFactory::getDefaultCaller()->signedCall('auth.getSession'array(
  63.             'token' => $token
  64.         ));
  65.  
  66.         return Session::fromSimpleXMLElement($xml);
  67.     }
  68.  
  69.     /** Fetch an unauthorized request token for an API account. This is step 2 of the authentication process for desktop applications. Web applications do not need to use this service.
  70.      *
  71.      * @return    string    A 32-character ASCII hexadecimal MD5 hash.
  72.      *
  73.      * @static
  74.      * @access    public
  75.      * @throws    Error
  76.      */
  77.     public static function getToken(){
  78.         $xml CallerFactory::getDefaultCaller()->signedCall('auth.getToken');
  79.  
  80.         return Util::toString($xml);
  81.     }
  82.  
  83.     /** Used by our flash embeds (on trusted domains) to use a site session cookie to seed a ws session without requiring a password. Uses the site cookie so must be accessed over a *.last.fm domain.
  84.      *
  85.      * @return    Session    A Session object.
  86.      *
  87.      * @static
  88.      * @access    public
  89.      * @throws    Error
  90.      */
  91.     public static function getWebSession(){
  92.         $xml CallerFactory::getDefaultCaller()->signedCall('auth.getWebSession');
  93.  
  94.         return Session::fromSimpleXMLElement($xml);
  95.     }
  96. }
  97.  
  98. ?>

Documentation generated on Mon, 22 Dec 2008 16:57:31 +0100 by phpDocumentor 1.4.1