/** * {@inheritDoc} * * @throws InvalidArgumentException */ public function preSend(RequestInterface $request) { // Skip by default if (null === $this->method) { return; } switch ($this->method) { case Client::AUTH_HTTP_TOKEN: $request->addHeader('PRIVATE-TOKEN: ' . $this->token); if (!is_null($this->sudo)) { $request->addHeader('SUDO: ' . $this->sudo); } break; case Client::AUTH_URL_TOKEN: $url = $request->getUrl(); $query = array('private_token' => $this->token); if (!is_null($this->sudo)) { $query['sudo'] = $this->sudo; } $url .= (false === strpos($url, '?') ? '?' : '&') . utf8_encode(http_build_query($query, '', '&')); $request->fromUrl(new Url($url)); break; case Client::AUTH_OAUTH_TOKEN: $request->addHeader('Authorization: Bearer ' . $this->token); if (!is_null($this->sudo)) { $request->addHeader('SUDO: ' . $this->sudo); } break; } }
/** * {@inheritDoc} * * @throws InvalidArgumentException */ public function preSend(RequestInterface $request) { // Skip by default if (null === $this->method) { return; } switch ($this->method) { case Client::AUTH_HTTP_PASSWORD: if (!isset($this->options['tokenOrLogin'], $this->options['password'])) { throw new InvalidArgumentException('You need to set username with password!'); } $request->addHeader('Authorization: Basic ' . base64_encode($this->options['tokenOrLogin'] . ':' . $this->options['password'])); break; case Client::AUTH_HTTP_TOKEN: if (!isset($this->options['tokenOrLogin'])) { throw new InvalidArgumentException('You need to set OAuth token!'); } $request->addHeader('Authorization: token ' . $this->options['tokenOrLogin']); break; case Client::AUTH_URL_CLIENT_ID: if (!isset($this->options['tokenOrLogin'], $this->options['password'])) { throw new InvalidArgumentException('You need to set client_id and client_secret!'); } $this->setRequestUrl($request, array('client_id' => $this->options['tokenOrLogin'], 'client_secret' => $this->options['password'])); break; case Client::AUTH_URL_TOKEN: if (!isset($this->options['tokenOrLogin'])) { throw new InvalidArgumentException('You need to set OAuth token!'); } $this->setRequestUrl($request, array('access_token' => $this->options['tokenOrLogin'])); break; default: throw new InvalidArgumentException(sprintf('Unknown method called "%s".', $this->method)); } }
public function preSend(RequestInterface $request) { $raw = $request->getContent(); $url = new Url($this->apiBaseUrl . $request->getResource() . '.json'); $request->setContent(json_encode($raw)); $request->setHost($url->getHost()); $request->setResource($url->getResource()); $request->addHeader('Authorization: Bearer ' . $this->token); $request->addHeader('Accept: application/json'); $request->addHeader('Content-Type: application/json'); }
public function preSend(RequestInterface $request) { if ($this->username === null) { throw new \RuntimeException("You have to setCredentials before using WsseListener with Buzz"); } $username = $this->username; $created = date('c'); $nonce = substr(md5(uniqid('nonce_', true)), 0, 16); $nonce64 = base64_encode($nonce); $passwordDigest = base64_encode(sha1($nonce . $created . $this->password, true)); $request->addHeader('Authorization: WSSE profile="UsernameToken"'); $header = "X-WSSE: UsernameToken Username=\"{$username}\", PasswordDigest=\"{$passwordDigest}\", Nonce=\"{$nonce64}\", Created=\"{$created}\""; $request->addHeader($header); }
/** * {@inheritDoc} */ public function preSend(RequestInterface $request) { $content = $request->getContent(); if (is_array($content) || $content instanceof \JsonSerializable) { $request->setContent(Json::encode($content)); $request->addHeader('Content-Type: application/json'); } }
/** * Populates uri, method and entityBody used to generate the Authentication header using the specified request object. * Appends the Authentication header if it is present and has been able to be calculated. * * @param RequestInterface $request A request object */ public function preSend(RequestInterface $request) { $this->setUri($request->getResource()); $this->setMethod($request->getMethod()); $this->setEntityBody($request->getContent()); $header = $this->getHeader(); if ($header) { $request->addHeader($header); } }
/** * {@inheritDoc} * * @throws InvalidArgumentException */ public function preSend(RequestInterface $request) { if (null === $this->method) { return; } switch ($this->method) { case Client::AUTH_HTTP_PASSWORD: if (!isset($this->options['login'], $this->options['password'])) { throw new InvalidArgumentException('You need to set username with password!'); } $request->addHeader('Authorization: Basic ' . base64_encode($this->options['login'] . ':' . $this->options['password'])); break; case Client::AUTH_HTTP_TOKEN: if (!isset($this->options['token'])) { throw new InvalidArgumentException('You need to set OAuth token!'); } $request->addHeader('Authorization: token ' . $this->options['token']); break; case Client::AUTH_URL_CLIENT_ID: if (!isset($this->options['login'], $this->options['password'])) { throw new InvalidArgumentException('You need to set client_id and client_secret!'); } if ('GET' === $request->getMethod()) { $url = $request->getUrl(); $parameters = array('client_id' => $this->options['login'], 'client_secret' => $this->options['password']); $url .= (false === strpos($url, '?') ? '?' : '&') . utf8_encode(http_build_query($parameters, '', '&')); $request->fromUrl(new Url($url)); } break; case Client::AUTH_URL_TOKEN: if (!isset($this->options['token'])) { throw new InvalidArgumentException('You need to set OAuth token!'); } if ('GET' === $request->getMethod()) { $url = $request->getUrl(); $parameters = array('access_token' => $this->options['token']); $url .= (false === strpos($url, '?') ? '?' : '&') . utf8_encode(http_build_query($parameters, '', '&')); $request->fromUrl(new Url($url)); } break; } }
/** * {@inheritDoc} */ public function preSend(RequestInterface $request) { switch ($this->method) { case Client::AUTH_HTTP_PASSWORD: $request->addHeader('Authorization: Basic ' . base64_encode($this->options['login'] . ':' . $this->options['password'])); break; case Client::AUTH_HTTP_TOKEN: $request->addHeader('Authorization: token ' . $this->options['token']); break; case Client::AUTH_URL_TOKEN: default: $url = $request->getUrl(); if ('GET' === $request->getMethod()) { $parameters = array('access_token' => $this->options['token']); $url .= '?' . utf8_encode(http_build_query($parameters, '', '&')); } $request->fromUrl(new Url($url)); break; } }
/** * @param RequestInterface $request */ public function preSend(RequestInterface $request) { // Skip by default if (null === $this->method) { return; } switch ($this->method) { case Client::AUTH_BASIC_TOKEN: $request->addHeader('Authorization: Basic ' . base64_encode($this->username . ':' . $this->password)); break; } }
/** * {@inheritDoc} * * @throws ForbiddenAccessException * @throws \InvalidArgumentException */ public function preSend(RequestInterface $request) { if (($oauth2Header = $request->getHeader('Authorization')) && strpos($oauth2Header, 'Bearer') !== false) { return; } if (false === array_key_exists('access_token', self::$config)) { try { $data = $this->getAccessToken(); self::$config['token_type'] = $data['token_type']; self::$config['access_token'] = $data['access_token']; } catch (HttpResponseException $e) { throw new ForbiddenAccessException("Can't fetch access_token.", 0, $e); } } $request->addHeader(sprintf('Authorization: %s %s', ucfirst(strtolower(self::$config['token_type'])), self::$config['access_token'])); }
/** * @param \Buzz\Message\RequestInterface $oRequest */ public function preSend(\Buzz\Message\RequestInterface $oRequest) { // Skip by default if (!$this->hasMethod()) { return; } switch ($this->getMethod()) { case \GitlabCI\Client::AUTH_HTTP_TOKEN: $oRequest->addHeader('PRIVATE-TOKEN: ' . $this->getToken()); $sUrl = $oRequest->getUrl(); $aQuery = array('url' => $this->getGitlabUrl()); $sUrl .= (false === strpos($sUrl, '?') ? '?' : '&') . utf8_encode(http_build_query($aQuery, '', '&')); $oRequest->fromUrl(new \Buzz\Util\Url($sUrl)); break; case \GitlabCI\Client::AUTH_URL_TOKEN: $aQuery = array('private_token' => $this->getToken(), 'url' => $this->getGitlabUrl()); $sUrl = $oRequest->getUrl(); $sUrl .= (false === strpos($sUrl, '?') ? '?' : '&') . utf8_encode(http_build_query($aQuery, '', '&')); $oRequest->fromUrl(new \Buzz\Util\Url($sUrl)); break; } }
/** * Execute before send request. * * @param RequestInterface $request Request instance */ public function preSend(RequestInterface $request) { $request->addHeader('access_token: ' . $this->token); }
/** * {@inheritdoc} */ public function authenticate(RequestInterface $request) { if (strpos($this->authHeader, 'OAuth') === false) { $this->authHeader = 'OAuth ' . $this->authHeader; } $request->addHeader('Authorization: ' . $this->authHeader); return $request; }
/** * {@inheritdoc} * * @param $request mixed \RequestInterface instance */ public function preSend(RequestInterface $request) { $request->addHeader(sprintf('app_id:%s', $this->app)); $request->addHeader(sprintf('app_key:%s', $this->key)); }
/** * {@inheritdoc} */ public function preSend(RequestInterface $request) { $request->addHeader(sprintf('Authorization: Bearer %s', $this->token)); }
/** * {@inheritdoc} */ public function authenticate(RequestInterface $request) { $request->addHeader('Authorization: Basic ' . base64_encode($this->username . ':' . $this->password)); return $request; }
public function preSend(RequestInterface $request) { $request->addHeader(sprintf('%s: %s', self::AUTH_TOKEN_NAME, $this->token)); }
public function preSend(RequestInterface $request) { $request->addHeader('Authorization: Basic ' . base64_encode($this->username . ':' . $this->password)); }