ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
Auth_OpenID_Message Class Reference
+ Collaboration diagram for Auth_OpenID_Message:

Public Member Functions

 Auth_OpenID_Message ($openid_namespace=null)
 
 isOpenID1 ()
 
 isOpenID2 ()
 
 _fromOpenIDArgs ($openid_args)
 @access private More...
 
 _getDefaultNamespace ($mystery_alias)
 
 setOpenIDNamespace ($openid_ns_uri, $implicit)
 
 getOpenIDNamespace ()
 
 copy ()
 
 toPostArgs ()
 
 toArgs ()
 
 toFormMarkup ($action_url, $form_tag_attrs=null, $submit_text="Continue")
 
 toURL ($base_url)
 
 toKVForm ()
 
 toURLEncoded ()
 
 _fixNS ($namespace)
 @access private More...
 
 hasKey ($namespace, $ns_key)
 
 getKey ($namespace, $ns_key)
 
 getArg ($namespace, $key, $default=null)
 
 getArgs ($namespace)
 
 updateArgs ($namespace, $updates)
 
 setArg ($namespace, $key, $value)
 
 delArg ($namespace, $key)
 
 getAliasedArg ($aliased_key, $default=null)
 

Static Public Member Functions

static fromPostArgs ($args)
 
static fromOpenIDArgs ($openid_args)
 
static fromKVForm ($kvform_string)
 

Detailed Description

Definition at line 414 of file Message.php.

Member Function Documentation

◆ _fixNS()

Auth_OpenID_Message::_fixNS (   $namespace)

@access private

Definition at line 728 of file Message.php.

730 {
731 // Convert an input value into the internally used values of
732 // this object
733
735 if ($this->_openid_ns_uri === null) {
736 return new Auth_OpenID_FailureResponse(null,
737 'OpenID namespace not set');
738 } else {
739 $namespace = $this->_openid_ns_uri;
740 }
741 }
742
744 (!is_string($namespace))) {
745 //TypeError
746 $err_msg = sprintf("Namespace must be Auth_OpenID_BARE_NS, ".
747 "Auth_OpenID_OPENID_NS or a string. got %s",
748 print_r($namespace, true));
749 return new Auth_OpenID_FailureResponse(null, $err_msg);
750 }
751
753 (strpos($namespace, ':') === false)) {
754 // fmt = 'OpenID 2.0 namespace identifiers SHOULD be URIs. Got %r'
755 // warnings.warn(fmt % (namespace,), DeprecationWarning)
756
757 if ($namespace == 'sreg') {
758 // fmt = 'Using %r instead of "sreg" as namespace'
759 // warnings.warn(fmt % (SREG_URI,), DeprecationWarning,)
761 }
762 }
763
764 return $namespace;
const Auth_OpenID_SREG_URI
Definition: Message.php:22
const Auth_OpenID_OPENID_NS
Definition: Message.php:42
const Auth_OpenID_BARE_NS
Definition: Message.php:46
if($err=$client->getError()) $namespace

Referenced by delArg(), getArg(), getArgs(), getKey(), hasKey(), setArg(), and updateArgs().

+ Here is the caller graph for this function:

◆ _fromOpenIDArgs()

Auth_OpenID_Message::_fromOpenIDArgs (   $openid_args)

@access private

Definition at line 495 of file Message.php.

497 {
499
500 // Takes an Auth_OpenID_Mapping instance OR an array.
501
502 if (!Auth_OpenID_Mapping::isA($openid_args)) {
503 $openid_args = new Auth_OpenID_Mapping($openid_args);
504 }
505
506 $ns_args = array();
507
508 // Resolve namespaces
509 foreach ($openid_args->items() as $pair) {
510 list($rest, $value) = $pair;
511
512 $parts = explode('.', $rest, 2);
513
514 if (count($parts) == 2) {
515 list($ns_alias, $ns_key) = $parts;
516 } else {
517 $ns_alias = Auth_OpenID_NULL_NAMESPACE;
518 $ns_key = $rest;
519 }
520
521 if ($ns_alias == 'ns') {
522 if ($this->namespaces->addAlias($value, $ns_key) === null) {
523 return false;
524 }
525 } else if (($ns_alias == Auth_OpenID_NULL_NAMESPACE) &&
526 ($ns_key == 'ns')) {
527 // null namespace
528 if ($this->setOpenIDNamespace($value, false) === false) {
529 return false;
530 }
531 } else {
532 $ns_args[] = array($ns_alias, $ns_key, $value);
533 }
534 }
535
536 if (!$this->getOpenIDNamespace()) {
537 if ($this->setOpenIDNamespace(Auth_OpenID_OPENID1_NS, true) ===
538 false) {
539 return false;
540 }
541 }
542
543 // Actually put the pairs into the appropriate namespaces
544 foreach ($ns_args as $triple) {
545 list($ns_alias, $ns_key, $value) = $triple;
546 $ns_uri = $this->namespaces->getNamespaceURI($ns_alias);
547 if ($ns_uri === null) {
548 $ns_uri = $this->_getDefaultNamespace($ns_alias);
549 if ($ns_uri === null) {
550
551 $ns_uri = Auth_OpenID_OPENID_NS;
552 $ns_key = sprintf('%s.%s', $ns_alias, $ns_key);
553 } else {
554 $this->namespaces->addAlias($ns_uri, $ns_alias, true);
555 }
556 }
557
558 $this->setArg($ns_uri, $ns_key, $value);
559 }
560
561 return true;
global $Auth_OpenID_registered_aliases
Definition: Message.php:67
const Auth_OpenID_OPENID1_NS
Definition: Message.php:25
const Auth_OpenID_NULL_NAMESPACE
Definition: Message.php:39
static isA($thing)
Returns true if $thing is an Auth_OpenID_Mapping object; false if not.
Definition: Message.php:145
_getDefaultNamespace($mystery_alias)
Definition: Message.php:563
setOpenIDNamespace($openid_ns_uri, $implicit)
Definition: Message.php:572
setArg($namespace, $key, $value)
Definition: Message.php:860
$rest
Definition: goto.php:85

◆ _getDefaultNamespace()

Auth_OpenID_Message::_getDefaultNamespace (   $mystery_alias)

Definition at line 563 of file Message.php.

565 {
567 if ($this->isOpenID1()) {
568 return @$Auth_OpenID_registered_aliases[$mystery_alias];
569 }
570 return null;

References $Auth_OpenID_registered_aliases, and isOpenID1().

+ Here is the call graph for this function:

◆ Auth_OpenID_Message()

Auth_OpenID_Message::Auth_OpenID_Message (   $openid_namespace = null)

Definition at line 416 of file Message.php.

418 {
419 // Create an empty Message
420 $this->allowed_openid_namespaces = array(
424
425 $this->args = new Auth_OpenID_Mapping();
426 $this->namespaces = new Auth_OpenID_NamespaceMap();
427 if ($openid_namespace === null) {
428 $this->_openid_ns_uri = null;
429 } else {
430 $implicit = Auth_OpenID_isOpenID1($openid_namespace);
431 $this->setOpenIDNamespace($openid_namespace, $implicit);
432 }
const Auth_OpenID_THE_OTHER_OPENID1_NS
Definition: Message.php:26
Auth_OpenID_isOpenID1($ns)
Definition: Message.php:28
const Auth_OpenID_OPENID2_NS
Definition: Message.php:35

References Auth_OpenID_isOpenID1(), Auth_OpenID_OPENID1_NS, Auth_OpenID_OPENID2_NS, Auth_OpenID_THE_OTHER_OPENID1_NS, and setOpenIDNamespace().

Referenced by fromOpenIDArgs(), and fromPostArgs().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ copy()

Auth_OpenID_Message::copy ( )

Definition at line 603 of file Message.php.

605 {
606 return $this;

◆ delArg()

Auth_OpenID_Message::delArg (   $namespace,
  $key 
)

Definition at line 876 of file Message.php.

878 {
879 $namespace = $this->_fixNS($namespace);
880
882 return $namespace;
883 } else {
884 return $this->args->del(array($namespace, $key));
885 }
_fixNS($namespace)
@access private
Definition: Message.php:728
static isFailure($thing)
Return true if $thing is an Auth_OpenID_FailureResponse object; false if not.
Definition: OpenID.php:118

References $namespace, _fixNS(), and Auth_OpenID\isFailure().

+ Here is the call graph for this function:

◆ fromKVForm()

static Auth_OpenID_Message::fromKVForm (   $kvform_string)
static

Definition at line 596 of file Message.php.

598 {
599 // Create a Message from a KVForm string
601 Auth_OpenID_KVForm::toArray($kvform_string));
static toArray($kvs, $strict=false)
Convert an OpenID colon/newline separated string into an associative array.
Definition: KVForm.php:29
static fromOpenIDArgs($openid_args)
Definition: Message.php:479

References fromOpenIDArgs(), and Auth_OpenID_KVForm\toArray().

Referenced by Auth_OpenID_GenericConsumer\_httpResponseToMessage().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fromOpenIDArgs()

static Auth_OpenID_Message::fromOpenIDArgs (   $openid_args)
static

Definition at line 479 of file Message.php.

481 {
482 // Takes an array.
483
484 // Construct a Message from a parsed KVForm message
485 $obj = new Auth_OpenID_Message();
486 if ($obj->_fromOpenIDArgs($openid_args)) {
487 return $obj;
488 } else {
489 return null;
490 }
Auth_OpenID_Message($openid_namespace=null)
Definition: Message.php:416

References Auth_OpenID_Message().

Referenced by Auth_OpenID_GenericConsumer\_createAssociateRequest(), and fromKVForm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fromPostArgs()

static Auth_OpenID_Message::fromPostArgs (   $args)
static

Definition at line 444 of file Message.php.

446 {
447 // Construct a Message containing a set of POST arguments
448 $obj = new Auth_OpenID_Message();
449
450 // Partition into "openid." args and bare args
451 $openid_args = array();
452 foreach ($args as $key => $value) {
453
454 if (is_array($value)) {
455 return null;
456 }
457
458 $parts = explode('.', $key, 2);
459
460 if (count($parts) == 2) {
461 list($prefix, $rest) = $parts;
462 } else {
463 $prefix = null;
464 }
465
466 if ($prefix != 'openid') {
467 $obj->args->set(array(Auth_OpenID_BARE_NS, $key), $value);
468 } else {
469 $openid_args[$rest] = $value;
470 }
471 }
472
473 if ($obj->_fromOpenIDArgs($openid_args)) {
474 return $obj;
475 } else {
476 return null;
477 }

References $rest, Auth_OpenID_BARE_NS, and Auth_OpenID_Message().

Referenced by Auth_OpenID_GenericConsumer\_verifyReturnToArgs(), Auth_OpenID_Consumer\complete(), and Auth_OpenID_Decoder\decode().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAliasedArg()

Auth_OpenID_Message::getAliasedArg (   $aliased_key,
  $default = null 
)

Definition at line 887 of file Message.php.

889 {
890 if ($aliased_key == 'ns') {
891 // Return the namespace URI for the OpenID namespace
892 return $this->getOpenIDNamespace();
893 }
894
895 $parts = explode('.', $aliased_key, 2);
896
897 if (count($parts) != 2) {
898 $ns = null;
899 } else {
900 list($alias, $key) = $parts;
901
902 if ($alias == 'ns') {
903 // Return the namespace URI for a namespace alias
904 // parameter.
905 return $this->namespaces->getNamespaceURI($key);
906 } else {
907 $ns = $this->namespaces->getNamespaceURI($alias);
908 }
909 }
910
911 if ($ns === null) {
912 $key = $aliased_key;
913 $ns = $this->getOpenIDNamespace();
914 }
915
916 return $this->getArg($ns, $key, $default);
getArg($namespace, $key, $default=null)
Definition: Message.php:804

References getArg(), and getOpenIDNamespace().

+ Here is the call graph for this function:

◆ getArg()

Auth_OpenID_Message::getArg (   $namespace,
  $key,
  $default = null 
)

Definition at line 804 of file Message.php.

806 {
807 // Get a value for a namespaced key.
808 $namespace = $this->_fixNS($namespace);
809
811 return $namespace;
812 } else {
813 if ((!$this->args->contains(array($namespace, $key))) &&
814 ($default == Auth_OpenID_NO_DEFAULT)) {
815 $err_msg = sprintf("Namespace %s missing required field %s",
816 $namespace, $key);
817 return new Auth_OpenID_FailureResponse(null, $err_msg);
818 } else {
819 return $this->args->get(array($namespace, $key), $default);
820 }
821 }
const Auth_OpenID_NO_DEFAULT
Definition: Message.php:50

References $namespace, _fixNS(), Auth_OpenID_NO_DEFAULT, and Auth_OpenID\isFailure().

Referenced by getAliasedArg().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getArgs()

Auth_OpenID_Message::getArgs (   $namespace)

Definition at line 823 of file Message.php.

825 {
826 // Get the arguments that are defined for this namespace URI
827
828 $namespace = $this->_fixNS($namespace);
830 return $namespace;
831 } else {
832 $stuff = array();
833 foreach ($this->args->items() as $pair) {
834 list($key, $value) = $pair;
835 list($pair_ns, $ns_key) = $key;
836 if ($pair_ns == $namespace) {
837 $stuff[$ns_key] = $value;
838 }
839 }
840
841 return $stuff;
842 }

References $namespace, _fixNS(), and Auth_OpenID\isFailure().

+ Here is the call graph for this function:

◆ getKey()

Auth_OpenID_Message::getKey (   $namespace,
  $ns_key 
)

Definition at line 777 of file Message.php.

779 {
780 // Get the key for a particular namespaced argument
781 $namespace = $this->_fixNS($namespace);
783 return $namespace;
784 }
786 return $ns_key;
787 }
788
789 $ns_alias = $this->namespaces->getAlias($namespace);
790
791 // No alias is defined, so no key can exist
792 if ($ns_alias === null) {
793 return null;
794 }
795
796 if ($ns_alias == Auth_OpenID_NULL_NAMESPACE) {
797 $tail = $ns_key;
798 } else {
799 $tail = sprintf('%s.%s', $ns_alias, $ns_key);
800 }
801
802 return 'openid.' . $tail;

References $namespace, _fixNS(), Auth_OpenID_BARE_NS, Auth_OpenID_NULL_NAMESPACE, and Auth_OpenID\isFailure().

Referenced by toPostArgs().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getOpenIDNamespace()

Auth_OpenID_Message::getOpenIDNamespace ( )

Definition at line 591 of file Message.php.

593 {
594 return $this->_openid_ns_uri;

Referenced by getAliasedArg(), isOpenID1(), and isOpenID2().

+ Here is the caller graph for this function:

◆ hasKey()

Auth_OpenID_Message::hasKey (   $namespace,
  $ns_key 
)

Definition at line 766 of file Message.php.

768 {
769 $namespace = $this->_fixNS($namespace);
771 // XXX log me
772 return false;
773 } else {
774 return $this->args->contains(array($namespace, $ns_key));
775 }

References $namespace, _fixNS(), and Auth_OpenID\isFailure().

+ Here is the call graph for this function:

◆ isOpenID1()

Auth_OpenID_Message::isOpenID1 ( )

Definition at line 434 of file Message.php.

436 {

References Auth_OpenID_isOpenID1(), and getOpenIDNamespace().

Referenced by _getDefaultNamespace().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isOpenID2()

Auth_OpenID_Message::isOpenID2 ( )

Definition at line 439 of file Message.php.

441 {

References Auth_OpenID_OPENID2_NS, and getOpenIDNamespace().

+ Here is the call graph for this function:

◆ setArg()

Auth_OpenID_Message::setArg (   $namespace,
  $key,
  $value 
)

Definition at line 860 of file Message.php.

862 {
863 // Set a single argument in this namespace
864 $namespace = $this->_fixNS($namespace);
865
867 return $namespace;
868 } else {
869 $this->args->set(array($namespace, $key), $value);
871 $this->namespaces->add($namespace);
872 }
873 return true;
874 }

References $namespace, _fixNS(), Auth_OpenID_BARE_NS, and Auth_OpenID\isFailure().

Referenced by updateArgs().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setOpenIDNamespace()

Auth_OpenID_Message::setOpenIDNamespace (   $openid_ns_uri,
  $implicit 
)

Definition at line 572 of file Message.php.

574 {
575 if (!in_array($openid_ns_uri, $this->allowed_openid_namespaces)) {
576 Auth_OpenID::log('Invalid null namespace: "%s"', $openid_ns_uri);
577 return false;
578 }
579
580 $succeeded = $this->namespaces->addAlias($openid_ns_uri,
582 $implicit);
583 if ($succeeded === false) {
584 return false;
585 }
586
587 $this->_openid_ns_uri = $openid_ns_uri;
588
589 return true;
static log($format_string)
Wrap PHP's standard error_log functionality.
Definition: OpenID.php:525

References Auth_OpenID_NULL_NAMESPACE, and Auth_OpenID\log().

Referenced by Auth_OpenID_Message().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toArgs()

Auth_OpenID_Message::toArgs ( )

Definition at line 639 of file Message.php.

641 {
642 // Return all namespaced arguments, failing if any
643 // non-namespaced arguments exist.
644 $post_args = $this->toPostArgs();
645 $kvargs = array();
646 foreach ($post_args as $k => $v) {
647 if (strpos($k, 'openid.') !== 0) {
648 // raise ValueError(
649 // 'This message can only be encoded as a POST, because it '
650 // 'contains arguments that are not prefixed with "openid."')
651 return null;
652 } else {
653 $kvargs[substr($k, 7)] = $v;
654 }
655 }
656
657 return $kvargs;

References toPostArgs().

Referenced by toKVForm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toFormMarkup()

Auth_OpenID_Message::toFormMarkup (   $action_url,
  $form_tag_attrs = null,
  $submit_text = "Continue" 
)

Definition at line 659 of file Message.php.

662 {
663 $form = "<form accept-charset=\"UTF-8\" ".
664 "enctype=\"application/x-www-form-urlencoded\"";
665
666 if (!$form_tag_attrs) {
667 $form_tag_attrs = array();
668 }
669
670 $form_tag_attrs['action'] = $action_url;
671 $form_tag_attrs['method'] = 'post';
672
673 unset($form_tag_attrs['enctype']);
674 unset($form_tag_attrs['accept-charset']);
675
676 if ($form_tag_attrs) {
677 foreach ($form_tag_attrs as $name => $attr) {
678 $form .= sprintf(" %s=\"%s\"", $name, $attr);
679 }
680 }
681
682 $form .= ">\n";
683
684 foreach ($this->toPostArgs() as $name => $value) {
685 $form .= sprintf(
686 "<input type=\"hidden\" name=\"%s\" value=\"%s\" />\n",
687 $name, $value);
688 }
689
690 $form .= sprintf("<input type=\"submit\" value=\"%s\" />\n",
691 $submit_text);
692
693 $form .= "</form>\n";
694
695 return $form;

References toPostArgs().

+ Here is the call graph for this function:

◆ toKVForm()

Auth_OpenID_Message::toKVForm ( )

Definition at line 704 of file Message.php.

706 {
707 // Generate a KVForm string that contains the parameters in
708 // this message. This will fail if the message contains
709 // arguments outside of the 'openid.' prefix.
710 return Auth_OpenID_KVForm::fromArray($this->toArgs());
static fromArray($values)
Convert an array into an OpenID colon/newline separated string.
Definition: KVForm.php:81

References Auth_OpenID_KVForm\fromArray(), and toArgs().

+ Here is the call graph for this function:

◆ toPostArgs()

Auth_OpenID_Message::toPostArgs ( )

Definition at line 608 of file Message.php.

610 {
611 // Return all arguments with openid. in front of namespaced
612 // arguments.
613
614 $args = array();
615
616 // Add namespace definitions to the output
617 foreach ($this->namespaces->iteritems() as $pair) {
618 list($ns_uri, $alias) = $pair;
619 if ($this->namespaces->isImplicit($ns_uri)) {
620 continue;
621 }
622 if ($alias == Auth_OpenID_NULL_NAMESPACE) {
623 $ns_key = 'openid.ns';
624 } else {
625 $ns_key = 'openid.ns.' . $alias;
626 }
627 $args[$ns_key] = $ns_uri;
628 }
629
630 foreach ($this->args->items() as $pair) {
631 list($ns_parts, $value) = $pair;
632 list($ns_uri, $ns_key) = $ns_parts;
633 $key = $this->getKey($ns_uri, $ns_key);
634 $args[$key] = $value;
635 }
636
637 return $args;
getKey($namespace, $ns_key)
Definition: Message.php:777

References Auth_OpenID_NULL_NAMESPACE, and getKey().

Referenced by toArgs(), toFormMarkup(), toURL(), and toURLEncoded().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toURL()

Auth_OpenID_Message::toURL (   $base_url)

Definition at line 697 of file Message.php.

699 {
700 // Generate a GET URL with the parameters in this message
701 // attached as query parameters.
702 return Auth_OpenID::appendArgs($base_url, $this->toPostArgs());
static appendArgs($url, $args)
"Appends" query arguments onto a URL.
Definition: OpenID.php:324

References Auth_OpenID\appendArgs(), and toPostArgs().

+ Here is the call graph for this function:

◆ toURLEncoded()

Auth_OpenID_Message::toURLEncoded ( )

Definition at line 712 of file Message.php.

714 {
715 // Generate an x-www-urlencoded string
716 $args = array();
717
718 foreach ($this->toPostArgs() as $k => $v) {
719 $args[] = array($k, $v);
720 }
721
722 sort($args);
723 return Auth_OpenID::httpBuildQuery($args);
static httpBuildQuery($data)
Implements the PHP 5 'http_build_query' functionality.
Definition: OpenID.php:296

References Auth_OpenID\httpBuildQuery(), and toPostArgs().

+ Here is the call graph for this function:

◆ updateArgs()

Auth_OpenID_Message::updateArgs (   $namespace,
  $updates 
)

Definition at line 844 of file Message.php.

846 {
847 // Set multiple key/value pairs in one call
848
849 $namespace = $this->_fixNS($namespace);
850
852 return $namespace;
853 } else {
854 foreach ($updates as $k => $v) {
855 $this->setArg($namespace, $k, $v);
856 }
857 return true;
858 }

References $namespace, _fixNS(), Auth_OpenID\isFailure(), and setArg().

+ Here is the call graph for this function:

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