/**
  * \brief Tokenエンドポイントリソース取得メソッド
  */
 public function fetchToken()
 {
     parent::setParam("grant_type", GrantType::REFRESH_TOKEN);
     parent::setParam("refresh_token", $this->refresh_token);
     parent::fetchToken();
     $res_body = parent::getResponse();
     // JSONパラメータ抽出処理
     $json_response = json_decode($res_body, true);
     Logger::debug("json response(" . get_class() . "::" . __FUNCTION__ . ")", $json_response);
     if ($json_response != null) {
         if (empty($json_response["error"])) {
             $access_token = $json_response["access_token"];
             $exp = $json_response["expires_in"];
             $this->access_token = new BearerToken($access_token, $exp);
         } else {
             $error = $json_response["error"];
             $error_desc = $json_response["error_description"];
             Logger::error($error . "(" . get_class() . "::" . __FUNCTION__ . ")", $error_desc);
             throw new TokenException($error, $error_desc);
         }
     } else {
         Logger::error("no_response(" . get_class() . "::" . __FUNCTION__ . ")", "Failed to get the response body");
         throw new TokenException("no_response", "Failed to get the response body");
     }
     Logger::debug("refresh token response(" . get_class() . "::" . __FUNCTION__ . ")", array($this->access_token));
     Logger::info("got access and refresh token(" . get_class() . "::" . __FUNCTION__ . ")");
 }
 /**
  * \brief 認可リクエストメソッド
  *
  * 認可サーバへAuthorozation Codeをリクエストします.
  *
  * @param	$redirect_uri	リダイレクトURI
  * @param	$state	state
  */
 public function requestAuthorizationGrant($redirect_uri = null, $state = null)
 {
     self::setParam("response_type", $this->response_type);
     self::setParam("client_id", $this->cred->id);
     // RECOMMENEDED
     if ($state != null) {
         self::setParam("state", $state);
     }
     // OPTIONAL
     if ($redirect_uri != null) {
         $encoded_redirect_uri = urlencode($redirect_uri);
         self::setParam("redirect_uri", $redirect_uri);
     }
     $query = http_build_query($this->params);
     $request_uri = $this->url . "?" . $query;
     Logger::info("authorization request(" . get_class() . "::" . __FUNCTION__ . ")", $request_uri);
     header("Location: " . $request_uri);
     exit;
 }
 /**
  * \brief Tokenエンドポイントリソース取得メソッド
  */
 public function fetchToken()
 {
     parent::setParam("grant_type", GrantType::AUTHORIZATION_CODE);
     parent::setParam("code", $this->code);
     parent::setParam("redirect_uri", $this->redirect_uri);
     parent::fetchToken();
     $res_body = parent::getResponse();
     // JSONパラメータ抽出処理
     $json_response = json_decode($res_body, true);
     Logger::debug("json response(" . get_class() . "::" . __FUNCTION__ . ")", $json_response);
     if ($json_response != null) {
         if (empty($json_response["error"])) {
             $access_token = $json_response["access_token"];
             $exp = $json_response["expires_in"];
             $refresh_token = $json_response["refresh_token"];
             $this->access_token = new BearerToken($access_token, $exp);
             $this->refresh_token = new RefreshToken($refresh_token);
             if (array_key_exists("id_token", $json_response)) {
                 $id_token = $json_response["id_token"];
                 $id_token_object = new IdToken($id_token, $this->cred->secret);
                 $this->id_token = $id_token_object->getIdToken();
             }
         } else {
             $error = $json_response["error"];
             $error_desc = $json_response["error_description"];
             Logger::error($error . "(" . get_class() . "::" . __FUNCTION__ . ")", $error_desc);
             throw new TokenException($error, $error_desc);
         }
     } else {
         Logger::error("no_response(" . get_class() . "::" . __FUNCTION__ . ")", "Failed to get the response body");
         throw new TokenException("no_response", "Failed to get the response body");
     }
     Logger::debug("token endpoint response(" . get_class() . "::" . __FUNCTION__ . ")", array($this->access_token, $this->refresh_token));
     Logger::info("got access and refresh token(" . get_class() . "::" . __FUNCTION__ . ")");
 }