123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- <?php
- require_once 'Auth/OpenID/Message.php';
- require_once 'Auth/OpenID/Extension.php';
- class Auth_OpenID_TeamsExtension extends Auth_OpenID_Extension {
- var $ns_uri = 'http://ns.launchpad.net/2007/openid-teams';
- var $ns_alias = 'lp';
- var $request_field = 'query_membership';
- var $response_field = 'is_member';
-
-
- function getExtensionArgs() {
- $args = array();
- if ($this->_teams) {
- $args[$this->request_field] = implode(',', $this->_teams);
- }
- return $args;
- }
-
- function toMessage(&$message) {
- if ($message->namespaces->addAlias($this->ns_uri, $this->ns_alias) === null) {
- if ($message->namespaces->getAlias($this->ns_uri) != $this->ns_alias) {
- return null;
- }
- }
- $message->updateArgs($this->ns_uri, $this->getExtensionArgs());
- return $message;
- }
-
-
- function _getExtensionNS(&$message) {
- $alias = null;
- $found_ns_uri = null;
-
- $alias = $message->namespaces->getAlias($this->ns_uri);
-
- if ($alias !== null) {
- $found_ns_uri = $this->ns_uri;
- }
- if ($alias === null) {
-
- $found_ns_uri = Auth_OpenID_TYPE_1_0;
-
- if ($message->namespaces->addAlias($this->ns_uri, $this->ns_alias) === null) {
-
-
- return null;
- }
- }
-
- return $found_ns_uri;
- }
- }
- class Auth_OpenID_TeamsRequest extends Auth_OpenID_TeamsExtension {
- function __init($teams) {
- if (!is_array($teams)) {
- if (!empty($teams)) {
- $teams = explode(',', $teams);
- } else {
- $teams = Array();
- }
- }
-
- $this->_teams = $teams;
- }
-
- function Auth_OpenID_TeamsRequest($teams) {
- $this->__init($teams);
- }
- }
- class Auth_OpenID_TeamsResponse extends Auth_OpenID_TeamsExtension {
- var $_teams = array();
-
- function __init(&$resp, $signed_only=true) {
- $this->ns_uri = $this->_getExtensionNS($resp->message);
-
- if ($signed_only) {
- $args = $resp->getSignedNS($this->ns_uri);
- } else {
- $args = $resp->message->getArgs($this->ns_uri);
- }
-
- if ($args === null) {
- return null;
- }
-
-
- if (in_array($this->response_field, array_keys($args)) && !empty($args[$this->response_field])) {
- $this->_teams = explode(',', $args[$this->response_field]);
- }
-
-
-
- elseif (in_array($this->ns_alias.'.'.$this->response_field, array_keys($args)) && !empty($args[$this->ns_alias.'.'.$this->response_field])) {
- $this->_teams = explode(',', $args[$this->ns_alias.'.'.$this->response_field]);
- }
- }
-
- function Auth_OpenID_TeamsResponse(&$resp, $signed_only=true) {
- $this->__init($resp, $signed_only);
- }
-
-
- function getTeams() {
- return $this->_teams;
- }
- }
- ?>
|