25 $this->signature_methods[$signature_method->get_name()] = $signature_method;
36 $this->get_version($request);
38 $consumer = $this->get_consumer($request);
43 $this->check_signature($request, $consumer, $token);
46 $callback = $request->get_parameter(
'oauth_callback');
47 $new_token = $this->data_store->new_request_token($consumer, $callback);
59 $this->get_version($request);
61 $consumer = $this->get_consumer($request);
64 $token = $this->get_token($request, $consumer,
"request");
66 $this->check_signature($request, $consumer, $token);
69 $verifier = $request->get_parameter(
'oauth_verifier');
70 $new_token = $this->data_store->new_access_token($token, $consumer, $verifier);
81 $this->get_version($request);
82 $consumer = $this->get_consumer($request);
83 $token = $this->get_token($request, $consumer,
"access");
84 $this->check_signature($request, $consumer, $token);
86 return array($consumer, $token);
94 private function get_version(&$request) {
96 $version = $request->get_parameter(
"oauth_version");
103 throw new OAuthException(
"OAuth version '$version' not supported");
113 private function get_signature_method($request) {
118 if (!$signature_method) {
121 throw new OAuthException(
'No signature method parameter. This parameter is required');
124 if (!in_array($signature_method,
125 array_keys($this->signature_methods))) {
127 "Signature method '$signature_method' not supported " .
128 'try one of the following: ' .
129 implode(
', ', array_keys($this->signature_methods))
133 return $this->signature_methods[$signature_method];
140 private function get_consumer($request) {
145 if (!$consumer_key) {
149 $consumer = $this->data_store->lookup_consumer($consumer_key);
161 private function get_token($request, $consumer, $token_type=
"access") {
166 $token = $this->data_store->lookup_token($consumer, $token_type, $token_field);
168 throw new OAuthException(
"Invalid $token_type token: $token_field");
179 private function check_signature($request, $consumer, $token) {
189 $this->check_timestamp($timestamp);
190 $this->check_nonce($consumer, $token, $nonce, $timestamp);
192 $signature_method = $this->get_signature_method($request);
194 $signature = $request->get_parameter(
'oauth_signature');
195 $valid_sig = $signature_method->check_signature($request, $consumer, $token, $signature);
205 private function check_timestamp($timestamp) {
207 throw new OAuthException(
'Missing timestamp parameter. The parameter is required');
211 if (abs($now - $timestamp) > $this->timestamp_threshold) {
212 throw new OAuthException(
"Expired timestamp, yours $timestamp, ours $now");
220 private function check_nonce($consumer, $token, $nonce, $timestamp) {
223 throw new OAuthException(
'Missing nonce parameter. The parameter is required');
226 $found = $this->data_store->lookup_nonce($consumer, $token, $nonce, $timestamp);
add_signature_method($signature_method)
Class to represent an OAuth Exception.
fetch_request_token(&$request)
process a request_token request returns the request token on success
verify_request(&$request)
verify an api call, checks all the parameters
fetch_access_token(&$request)
process an access_token request returns the access token on success
Class to represent an OAuth Request.
Class to represent an OAuth Server.