Changed the caching expiration policy from a expiration on get to a TTL on set, and...
[shindig.git] / javascript / samplecontainer / examples / oauth.xml
blob1e1098c63f8bc6e54fd62ea5e19209404431d55a
1  <?xml version="1.0" encoding="UTF-8" ?>
2 <Module>
3   <ModulePrefs title="Demo OAuth Gadget">
4     <OAuth>
5       <Service>
6         <Request url="http://localhost:9090/oauth-provider/request_token" />
7         <Access url="http://localhost:9090/oauth-provider/access_token" />
8         <Authorization url="http://localhost:9090/oauth-provider/authorize?oauth_callback=http://localhost:8080/gadgets/oauthcallback" />
9       </Service>
10     </OAuth>
11     <Preload authz="oauth" href="http://localhost:9090/oauth-provider/echo" />
12   </ModulePrefs>
13   <Content type="html">
14       <![CDATA[
16     <style>
17     #main {
18         margin: 0px;
19         padding: 0px;
20         font-size: small;
21     }
22     </style>
24     <div id="main" style="display: none">
25     </div>
27     <div id="approval" style="display: none">
28       <img src="http://localhost:8080/gadgets/files/samplecontainer/examples/new.gif">
29       <a href="#" id="personalize">Personalize this gadget</a>
30     </div>
32     <div id="waiting" style="display: none">
33       Please click
34       <a href="#" id="approvaldone">I've approved access</a>
35       once you've approved access to your data.
36     </div>
38     <script src="http://localhost:8080/gadgets/files/samplecontainer/examples/popup.js"></script>
40     <script type="text/javascript">
41       function $(x) {
42         return document.getElementById(x);
43       }
45       function showOneSection(toshow) {
46         var sections = [ 'main', 'approval', 'waiting' ];
47         for (var i=0; i < sections.length; ++i) {
48           var s = sections[i];
49           var el = $(s);
50           if (s === toshow) {
51             el.style.display = "block";
52           } else {
53             el.style.display = "none";
54           }
55         }
56       }
58       function fetchData() {
59         url = "http://localhost:9090/oauth-provider/echo";
60         var params = {};
61         params[gadgets.io.RequestParameters.CONTENT_TYPE] =
62           gadgets.io.ContentType.TEXT;
63         params[gadgets.io.RequestParameters.AUTHORIZATION] =
64           gadgets.io.AuthorizationType.OAUTH;
65         params[gadgets.io.RequestParameters.METHOD] =
66           gadgets.io.MethodType.GET;
68         gadgets.io.makeRequest(url, function (response) {
69           var popup = null;
70           if (response.oauthApprovalUrl) {
71             popup = shindig.oauth.popup({
72               destination: response.oauthApprovalUrl,
73               windowOptions: null,
74               onOpen: function() { showOneSection('waiting'); },
75               onClose: function() { fetchData(); }
76             });
77             $('personalize').onclick = popup.createOpenerOnClick();
78             $('approvaldone').onclick = popup.createApprovedOnClick();
79             showOneSection('approval');
80           } else if (response.data) {
81             $('main').appendChild(document.createTextNode(response.data));
82             showOneSection('main');
83           } else {
84             var whoops = document.createTextNode(
85                 'OAuth error: ' + response.oauthError + ': ' +
86                 response.oauthErrorText);
87             $('main').appendChild(whoops);
88             showOneSection('main');
89           }
90         }, params);
91       }
93       gadgets.util.registerOnLoadHandler(fetchData);
94     </script>
95         ]]>
96   </Content>
97 </Module>