/** * Helper method to start the flow by redirecting the user to the * authentication server. The getAccessToken method must be used when the * server redirects the user back to the redirect uri * * @param \PSX\Url $url * @param string $clientId * @param string $redirectUri * @param string $scope * @param string $state */ public static function redirect(Url $url, $clientId, $redirectUri = null, $scope = null, $state = null) { $parameters = $url->getParameters(); $parameters['response_type'] = 'code'; $parameters['client_id'] = $clientId; if (isset($redirectUri)) { $parameters['redirect_uri'] = $redirectUri; } if (isset($scope)) { $parameters['scope'] = $scope; } if (isset($state)) { $parameters['state'] = $state; } throw new StatusCode\TemporaryRedirectException($url->withScheme('https')->withParameters($parameters)->toString()); }
/** * If you have established a token and token secret you can use this method * to get the authorization header. You can add the header to an http * request to make an valid oauth request i.e. * <code> * $header = array( * 'Authorization: ' . $oauth->getAuthorizationHeader(...), * ); * </code> * * @param \PSX\Url $url * @param string $consumerKey * @param string $consumerSecret * @param string $token * @param string $tokenSecret * @param string $method * @param string $requestMethod * @param array $post * @return string */ public function getAuthorizationHeader(Url $url, $consumerKey, $consumerSecret, $token, $tokenSecret, $method = 'HMAC-SHA1', $requestMethod = 'GET', array $post = array()) { $values = array('oauth_consumer_key' => $consumerKey, 'oauth_token' => $token, 'oauth_signature_method' => $method, 'oauth_timestamp' => self::getTimestamp(), 'oauth_nonce' => self::getNonce(), 'oauth_version' => self::getVersion()); // build the base string $params = array_merge($values, $url->getParameters()); if ($requestMethod == 'POST' && !empty($post)) { $params = array_merge($params, $post); } $baseString = self::buildBasestring($requestMethod, $url, $params); // get the signature object $signature = self::getSignature($method); // generate the signature $values['oauth_signature'] = $signature->build($baseString, $consumerSecret, $tokenSecret); // build request $authorizationHeader = 'OAuth realm="psx", ' . self::buildAuthString($values); return $authorizationHeader; }