ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
OAuthServer Class Reference
+ Inheritance diagram for OAuthServer:
+ Collaboration diagram for OAuthServer:

Public Member Functions

 __construct ($data_store)
 
 add_signature_method ($signature_method)
 
 fetch_request_token (&$request)
 process a request_token request returns the request token on success More...
 
 fetch_access_token (&$request)
 process an access_token request returns the access token on success More...
 
 verify_request (&$request)
 verify an api call, checks all the parameters More...
 

Protected Attributes

 $timestamp_threshold = 300
 
 $version = '1.0'
 
 $signature_methods = array()
 
 $data_store
 

Private Member Functions

 get_version (&$request)
 version 1 More...
 
 get_signature_method ($request)
 figure out the signature with some defaults More...
 
 get_consumer ($request)
 try to find the consumer for the provided request's consumer key More...
 
 get_token ($request, $consumer, $token_type="access")
 try to find the token for the provided request's token key More...
 
 check_signature ($request, $consumer, $token)
 all-in-one function to check the signature on a request should guess the signature method appropriately More...
 
 check_timestamp ($timestamp)
 check that the timestamp is new enough More...
 
 check_nonce ($consumer, $token, $nonce, $timestamp)
 check that the nonce is not repeated More...
 

Detailed Description

Definition at line 509 of file OAuth.php.

Constructor & Destructor Documentation

◆ __construct()

OAuthServer::__construct (   $data_store)

Definition at line 516 of file OAuth.php.

516  {
517  $this->data_store = $data_store;
518  }

Member Function Documentation

◆ add_signature_method()

OAuthServer::add_signature_method (   $signature_method)

Definition at line 520 of file OAuth.php.

520  {
521  $this->signature_methods[$signature_method->get_name()] =
522  $signature_method;
523  }

◆ check_nonce()

OAuthServer::check_nonce (   $consumer,
  $token,
  $nonce,
  $timestamp 
)
private

check that the nonce is not repeated

Definition at line 716 of file OAuth.php.

References $consumer, and $timestamp.

716  {
717  if( ! $nonce )
718  throw new OAuthException(
719  'Missing nonce parameter. The parameter is required'
720  );
721 
722  // verify that the nonce is uniqueish
723  $found = $this->data_store->lookup_nonce(
724  $consumer,
725  $token,
726  $nonce,
727  $timestamp
728  );
729  if ($found) {
730  throw new OAuthException("Nonce already used: $nonce");
731  }
732  }
$consumer
Definition: demo.php:30
foreach($mandatory_scripts as $file) $timestamp
Definition: buildRTE.php:81

◆ check_signature()

OAuthServer::check_signature (   $request,
  $consumer,
  $token 
)
private

all-in-one function to check the signature on a request should guess the signature method appropriately

Definition at line 668 of file OAuth.php.

References $consumer, $timestamp, and OAuthRequest\get_parameter().

668  {
669  // this should probably be in a different method
670  $timestamp = $request instanceof OAuthRequest
671  ? $request->get_parameter('oauth_timestamp')
672  : NULL;
673  $nonce = $request instanceof OAuthRequest
674  ? $request->get_parameter('oauth_nonce')
675  : NULL;
676 
677  $this->check_timestamp($timestamp);
678  $this->check_nonce($consumer, $token, $nonce, $timestamp);
679 
680  $signature_method = $this->get_signature_method($request);
681 
682  $signature = $request->get_parameter('oauth_signature');
683  $valid_sig = $signature_method->check_signature(
684  $request,
685  $consumer,
686  $token,
687  $signature
688  );
689 
690  if (!$valid_sig) {
691  throw new OAuthException("Invalid signature");
692  }
693  }
check_timestamp($timestamp)
check that the timestamp is new enough
Definition: OAuth.php:698
check_nonce($consumer, $token, $nonce, $timestamp)
check that the nonce is not repeated
Definition: OAuth.php:716
get_parameter($name)
Definition: OAuth.php:351
$consumer
Definition: demo.php:30
foreach($mandatory_scripts as $file) $timestamp
Definition: buildRTE.php:81
get_signature_method($request)
figure out the signature with some defaults
Definition: OAuth.php:600
+ Here is the call graph for this function:

◆ check_timestamp()

OAuthServer::check_timestamp (   $timestamp)
private

check that the timestamp is new enough

Definition at line 698 of file OAuth.php.

References $timestamp, and time.

698  {
699  if( ! $timestamp )
700  throw new OAuthException(
701  'Missing timestamp parameter. The parameter is required'
702  );
703 
704  // verify that timestamp is recentish
705  $now = time();
706  if (abs($now - $timestamp) > $this->timestamp_threshold) {
707  throw new OAuthException(
708  "Expired timestamp, yours $timestamp, ours $now"
709  );
710  }
711  }
foreach($mandatory_scripts as $file) $timestamp
Definition: buildRTE.php:81
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.

◆ fetch_access_token()

OAuthServer::fetch_access_token ( $request)

process an access_token request returns the access token on success

Definition at line 552 of file OAuth.php.

References $consumer.

552  {
553  $this->get_version($request);
554 
555  $consumer = $this->get_consumer($request);
556 
557  // requires authorized request token
558  $token = $this->get_token($request, $consumer, "request");
559 
560  $this->check_signature($request, $consumer, $token);
561 
562  // Rev A change
563  $verifier = $request->get_parameter('oauth_verifier');
564  $new_token = $this->data_store->new_access_token($token, $consumer, $verifier);
565 
566  return $new_token;
567  }
check_signature($request, $consumer, $token)
all-in-one function to check the signature on a request should guess the signature method appropriate...
Definition: OAuth.php:668
get_version(&$request)
version 1
Definition: OAuth.php:584
$consumer
Definition: demo.php:30
get_token($request, $consumer, $token_type="access")
try to find the token for the provided request's token key
Definition: OAuth.php:645
get_consumer($request)
try to find the consumer for the provided request's consumer key
Definition: OAuth.php:625

◆ fetch_request_token()

OAuthServer::fetch_request_token ( $request)

process a request_token request returns the request token on success

Definition at line 531 of file OAuth.php.

References $consumer.

531  {
532  $this->get_version($request);
533 
534  $consumer = $this->get_consumer($request);
535 
536  // no token required for the initial token request
537  $token = NULL;
538 
539  $this->check_signature($request, $consumer, $token);
540 
541  // Rev A change
542  $callback = $request->get_parameter('oauth_callback');
543  $new_token = $this->data_store->new_request_token($consumer, $callback);
544 
545  return $new_token;
546  }
check_signature($request, $consumer, $token)
all-in-one function to check the signature on a request should guess the signature method appropriate...
Definition: OAuth.php:668
get_version(&$request)
version 1
Definition: OAuth.php:584
$consumer
Definition: demo.php:30
get_consumer($request)
try to find the consumer for the provided request's consumer key
Definition: OAuth.php:625

◆ get_consumer()

OAuthServer::get_consumer (   $request)
private

try to find the consumer for the provided request's consumer key

Definition at line 625 of file OAuth.php.

References $consumer, and OAuthRequest\get_parameter().

625  {
626  $consumer_key = $request instanceof OAuthRequest
627  ? $request->get_parameter("oauth_consumer_key")
628  : NULL;
629 
630  if (!$consumer_key) {
631  throw new OAuthException("Invalid consumer key");
632  }
633 
634  $consumer = $this->data_store->lookup_consumer($consumer_key);
635  if (!$consumer) {
636  throw new OAuthException("Invalid consumer");
637  }
638 
639  return $consumer;
640  }
get_parameter($name)
Definition: OAuth.php:351
$consumer
Definition: demo.php:30
+ Here is the call graph for this function:

◆ get_signature_method()

OAuthServer::get_signature_method (   $request)
private

figure out the signature with some defaults

Definition at line 600 of file OAuth.php.

References OAuthRequest\get_parameter().

600  {
601  $signature_method = $request instanceof OAuthRequest
602  ? $request->get_parameter("oauth_signature_method")
603  : NULL;
604 
605  if (!$signature_method) {
606  // According to chapter 7 ("Accessing Protected Ressources") the signature-method
607  // parameter is required, and we can't just fallback to PLAINTEXT
608  throw new OAuthException('No signature method parameter. This parameter is required');
609  }
610 
611  if (!in_array($signature_method,
612  array_keys($this->signature_methods))) {
613  throw new OAuthException(
614  "Signature method '$signature_method' not supported " .
615  "try one of the following: " .
616  implode(", ", array_keys($this->signature_methods))
617  );
618  }
619  return $this->signature_methods[$signature_method];
620  }
get_parameter($name)
Definition: OAuth.php:351
+ Here is the call graph for this function:

◆ get_token()

OAuthServer::get_token (   $request,
  $consumer,
  $token_type = "access" 
)
private

try to find the token for the provided request's token key

Definition at line 645 of file OAuth.php.

References $consumer, and OAuthRequest\get_parameter().

645  {
646  $token_field = $request instanceof OAuthRequest
647  ? $request->get_parameter('oauth_token')
648  : NULL;
649 
650  if (!empty($token_field)) {
651  $token = $this->data_store->lookup_token(
652  $consumer, $token_type, $token_field
653  );
654  if (!$token) {
655  throw new OAuthException("Invalid $token_type token: $token_field");
656  }
657  }
658  else {
659  $token = new OAuthToken('', '');
660  }
661  return $token;
662  }
OAuth PECL extension includes an OAuth Exception class, so we need to wrap the definition of this cla...
Definition: OAuth.php:37
get_parameter($name)
Definition: OAuth.php:351
$consumer
Definition: demo.php:30
+ Here is the call graph for this function:

◆ get_version()

OAuthServer::get_version ( $request)
private

version 1

Definition at line 584 of file OAuth.php.

References $version.

584  {
585  $version = $request->get_parameter("oauth_version");
586  if (!$version) {
587  // Service Providers MUST assume the protocol version to be 1.0 if this parameter is not present.
588  // Chapter 7.0 ("Accessing Protected Ressources")
589  $version = '1.0';
590  }
591  if ($version !== $this->version) {
592  throw new OAuthException("OAuth version '$version' not supported");
593  }
594  return $version;
595  }

◆ verify_request()

OAuthServer::verify_request ( $request)

verify an api call, checks all the parameters

Definition at line 572 of file OAuth.php.

References $consumer, and array.

572  {
573  $this->get_version($request);
574  $consumer = $this->get_consumer($request);
575  $token = $this->get_token($request, $consumer, "access");
576  $this->check_signature($request, $consumer, $token);
577  return array($consumer, $token);
578  }
check_signature($request, $consumer, $token)
all-in-one function to check the signature on a request should guess the signature method appropriate...
Definition: OAuth.php:668
get_version(&$request)
version 1
Definition: OAuth.php:584
$consumer
Definition: demo.php:30
Create styles array
The data for the language used.
get_token($request, $consumer, $token_type="access")
try to find the token for the provided request's token key
Definition: OAuth.php:645
get_consumer($request)
try to find the consumer for the provided request's consumer key
Definition: OAuth.php:625

Field Documentation

◆ $data_store

OAuthServer::$data_store
protected

Definition at line 514 of file OAuth.php.

◆ $signature_methods

OAuthServer::$signature_methods = array()
protected

Definition at line 512 of file OAuth.php.

Referenced by sspmod_oauth_OAuthServer\get_signature_methods().

◆ $timestamp_threshold

OAuthServer::$timestamp_threshold = 300
protected

Definition at line 510 of file OAuth.php.

◆ $version

OAuthServer::$version = '1.0'
protected

Definition at line 511 of file OAuth.php.


The documentation for this class was generated from the following file: