]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/xrds.php
be1244bb3c98db15ec46cb8b3f234fabd20aa656
[quix0rs-gnu-social.git] / actions / xrds.php
1 <?php
2 /*
3  * Laconica - a distributed open-source microblogging tool
4  * Copyright (C) 2008, Controlez-Vous, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 if (!defined('LACONICA')) { exit(1); }
21
22 define('OAUTH_NAMESPACE', 'http://oauth.net/core/1.0/');
23 define('OMB_NAMESPACE', 'http://openmicroblogging.org/protocol/0.1');
24 define('OAUTH_DISCOVERY', 'http://oauth.net/discovery/1.0');
25
26 define('OMB_ENDPOINT_UPDATEPROFILE', OMB_NAMESPACE.'updateProfile');
27 define('OAUTH_ENDPOINT_REQUEST', OAUTH_NAMESPACE.'endpoint/request');
28 define('OAUTH_ENDPOINT_AUTHORIZE', OAUTH_NAMESPACE.'endpoint/authorize');
29 define('OAUTH_ENDPOINT_ACCESS', OAUTH_NAMESPACE.'endpoint/access');
30 define('OAUTH_ENDPOINT_RESOURCE', OAUTH_NAMESPACE.'endpoint/resource');
31 define('OAUTH_AUTH_HEADER', OAUTH_NAMESPACE.'parameters/auth-header');
32 define('OAUTH_POST_BODY', OAUTH_NAMESPACE.'parameters/post-body');
33 define('OAUTH_HMAC_SHA1', OAUTH_NAMESPACE.'signature/HMAC-SHA1');
34            
35 class XrdsAction extends Action {
36
37         function handle($args) {
38                 parent::handle($args);
39                 $nickname = $this->trimmed('nickname');
40                 $user = User::staticGet('nickname', $nickname);
41                 if (!$user) {
42                         common_user_error(_t('No such user.'));
43                         return;
44                 }
45                 $this->show_xrds($user);
46         }
47
48         function show_xrds($user) {
49                 
50                 header('Content-Type: application/rdf+xml');
51
52                 common_start_xml();
53                 common_element_start('XRDS', array('xmlns' => 'xri://$xrds'));
54                 
55                 common_element_start('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
56                                                   'xml:id' => 'oauth',
57                                                                                   'xmlns:simple' => 'http://xrds-simple.net/core/1.0',
58                                                                                   'version' => '2.0'));
59
60                 common_element('Type', NULL, 'xri://$xrds*simple');
61
62                 $this->show_service(OAUTH_ENDPONT_REQUEST,
63                                                         common_local_url('requesttoken'),
64                                                         array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY),
65                                                         array(OAUTH_HMAC_SHA1),
66                                                         $user->getUri());
67
68                 $this->show_service(OAUTH_ENDPONT_AUTHORIZE,
69                                                         common_local_url('userauthorization'),
70                                                         array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY),
71                                                         array(OAUTH_HMAC_SHA1),
72                                                         $user->getUri());
73
74                 $this->show_service(OAUTH_ENDPONT_ACCESS,
75                                                         common_local_url('accesstoken'),
76                                                         array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY),
77                                                         array(OAUTH_HMAC_SHA1));
78
79                 $this->show_service(OAUTH_ENDPONT_RESOURCE,
80                                                         NULL,
81                                                         array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY),
82                                                         array(OAUTH_HMAC_SHA1));
83                 
84                 common_element_end('XRD');
85                 
86                 # XXX: decide whether to include user's ID/nickname in postNotice URL
87                 
88                 common_element_start('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
89                                                   'xml:id' => 'omb',
90                                                                                   'xmlns:simple' => 'http://xrds-simple.net/core/1.0',
91                                                                                   'version' => '2.0'));
92                 
93                 common_element('Type', NULL, 'xri://$xrds*simple');
94                 
95                 $this->show_service(OMB_ENDPONT_POSTNOTICE,
96                                                         common_local_url('postnotice'));
97
98                 $this->show_service(OMB_ENDPONT_UPDATEPROFILE,
99                                                         common_local_url('updateprofile'));
100
101                 common_element_end('XRD');
102                 
103                 common_element_start('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
104                                                                                   'version' => '2.0'));
105
106                 common_element('Type', NULL, 'xri://$xrds*simple');
107                 
108                 $this->show_service(OAUTH_DISCOVERY,
109                                                         '#oauth');
110                 $this->show_service(OMB_NAMESPACE,
111                                                         '#omb');
112                 
113                 common_element_end('XRD');
114                 
115                 common_element_end('XRDS');
116                 common_end_xml();
117         }
118         
119         function show_service($type, $uri, $params=NULL, $signature=NULL, $localId=NULL) {
120                 common_element_start('Service');
121                 common_element('Type', $type);
122                 common_element('URI', $uri);
123                 common_element_end('Service');
124         }
125 }