コード例 #1
0
ファイル: Podio.php プロジェクト: xengine/podio-php
 public static function authenticate($grant_type, $attributes)
 {
     $data = array();
     $auth_type = array('type' => $grant_type);
     switch ($grant_type) {
         case 'password':
             $data['grant_type'] = 'password';
             $data['username'] = $attributes['username'];
             $data['password'] = $attributes['password'];
             $auth_type['identifier'] = $attributes['username'];
             break;
         case 'refresh_token':
             $data['grant_type'] = 'refresh_token';
             $data['refresh_token'] = $attributes['refresh_token'];
             break;
         case 'authorization_code':
             $data['grant_type'] = 'authorization_code';
             $data['code'] = $attributes['code'];
             $data['redirect_uri'] = $attributes['redirect_uri'];
             break;
         case 'app':
             $data['grant_type'] = 'app';
             $data['app_id'] = $attributes['app_id'];
             $data['app_token'] = $attributes['app_token'];
             $auth_type['identifier'] = $attributes['app_id'];
             break;
         default:
             break;
     }
     $request_data = array_merge($data, array('client_id' => self::$client_id, 'client_secret' => self::$client_secret));
     if ($response = self::request(self::POST, '/oauth/token', $request_data, array('oauth_request' => true))) {
         $body = $response->json_body();
         self::$oauth = new PodioOAuth($body['access_token'], $body['refresh_token'], $body['expires_in'], $body['ref']);
         // Don't touch auth_type if we are refreshing automatically as it'll be reset to null
         if ($grant_type !== 'refresh_token') {
             self::$auth_type = $auth_type;
         }
         return true;
     }
     return false;
 }