本文整理汇总了PHP中RequestUtil::doPostWithSpecificAuth方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestUtil::doPostWithSpecificAuth方法的具体用法?PHP RequestUtil::doPostWithSpecificAuth怎么用?PHP RequestUtil::doPostWithSpecificAuth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RequestUtil
的用法示例。
在下文中一共展示了RequestUtil::doPostWithSpecificAuth方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _finish
protected function _finish($code, $originalRedirectUri)
{
// This endpoint requires "Basic" auth.
$clientCredentials = $this->appInfo->getKey() . ":" . $this->appInfo->getSecret();
$authHeaderValue = "Basic " . base64_encode($clientCredentials);
$response = RequestUtil::doPostWithSpecificAuth($this->clientIdentifier, $authHeaderValue, $this->userLocale, $this->appInfo->getHost()->getApi(), "1/oauth2/token", array("grant_type" => "authorization_code", "code" => $code, "redirect_uri" => $originalRedirectUri));
if ($response->statusCode !== 200) {
throw RequestUtil::unexpectedStatus($response);
}
$parts = RequestUtil::parseResponseJson($response->body);
if (!array_key_exists('token_type', $parts) or !is_string($parts['token_type'])) {
throw new Exception_BadResponse("Missing \"token_type\" field.");
}
$tokenType = $parts['token_type'];
if (!array_key_exists('access_token', $parts) or !is_string($parts['access_token'])) {
throw new Exception_BadResponse("Missing \"access_token\" field.");
}
$accessToken = $parts['access_token'];
if (!array_key_exists('uid', $parts) or !is_string($parts['uid'])) {
throw new Exception_BadResponse("Missing \"uid\" string field.");
}
$userId = $parts['uid'];
if ($tokenType !== "Bearer" && $tokenType !== "bearer") {
throw new Exception_BadResponse("Unknown \"token_type\"; expecting \"Bearer\", got " . Client::q($tokenType));
}
return array($accessToken, $userId);
}
示例2: doPost
/**
* @param OAuth1AccessToken $oauth1AccessToken
* @param string $path
*
* @return HttpResponse
*
* @throws Exception
*/
private function doPost($oauth1AccessToken, $path)
{
// Construct the OAuth 1 header.
$signature = rawurlencode($this->appInfo->getSecret()) . "&" . rawurlencode($oauth1AccessToken->getSecret());
$authHeaderValue = "OAuth oauth_signature_method=\"PLAINTEXT\"" . ", oauth_consumer_key=\"" . rawurlencode($this->appInfo->getKey()) . "\"" . ", oauth_token=\"" . rawurlencode($oauth1AccessToken->getKey()) . "\"" . ", oauth_signature=\"" . $signature . "\"";
return RequestUtil::doPostWithSpecificAuth($this->clientIdentifier, $authHeaderValue, $this->userLocale, $this->appInfo->getHost()->getApi(), $path, null);
}