public function exchangeCode(Model\Server\ServerInterface $server, Model\App\ClientAppInterface $clientApp, $code) { list($apiRoot) = $server->servers(); $payload = array('code' => $code, 'token_type' => 'mac'); $response = $this->tentHttpClient->post($apiRoot . '/apps/' . $clientApp->id() . '/authorizations', null, json_encode($payload))->send(); $json = json_decode($response->getBody(), true); return new Dto\App\ClientAuthorizationResponse($clientApp, $this->authFactory->create($json['access_token'], $json['mac_key'], $json['mac_algorithm']), $json['token_type'], $json['refresh_token'], isset($json['tent_expires_at']) ? $json['tent_expires_at'] : null); }
public function putProfileInfoInternal(Model\Server\ServerInterface $server, $apiRoot, Model\Entity\ProfileInfoInterface $profileInfo) { $response = $this->tentHttpClient->put($apiRoot . '/profile/' . rawurlencode($profileInfo->uri()), null, json_encode($profileInfo->content())); $profileInfo = new Model\Entity\ProfileInfo($profileInfo->uri(), json_decode($response->body(), true)); if ($server instanceof Model\Server\EntityServer) { $server->entity()->profile()->set($profileInfo); } return $profileInfo; }
public static function tryAllServers(Model\Server\ServerInterface $server, $callback, $additionalArgs = null) { foreach ($server->servers() as $target) { $args = array($server, $target); if (null !== $additionalArgs) { $args = array_merge($args, $additionalArgs); } return call_user_func_array($callback, $args); } throw new \RuntimeException("Unable to send to any server"); }