Author: rgardler
Date: Mon Jan 30 23:39:57 2012
New Revision: 1238088

URL: http://svn.apache.org/viewvc?rev=1238088&view=rev
Log:
enable implicit grant in oAuth (complete with facebook scratchpad example) 
thanks to Hoang Minh Tien (fixes wookie-307)

Added:
    incubator/wookie/trunk/scratchpad/widgets/fbfriend/
    incubator/wookie/trunk/scratchpad/widgets/fbfriend/build.xml
    incubator/wookie/trunk/scratchpad/widgets/fbfriend/config.xml
    incubator/wookie/trunk/scratchpad/widgets/fbfriend/index.html
    incubator/wookie/trunk/scratchpad/widgets/fbfriend/scripts/
    incubator/wookie/trunk/scratchpad/widgets/fbfriend/scripts/main.js
    incubator/wookie/trunk/scratchpad/widgets/fbfriend/style/
    incubator/wookie/trunk/scratchpad/widgets/fbfriend/style/screen.css   (with 
props)
Modified:
    incubator/wookie/trunk/WebContent/WEB-INF/dwr.xml
    incubator/wookie/trunk/features/oauth/oauth.js
    incubator/wookie/trunk/src/org/apache/wookie/feature/oauth/oAuthClient.java

Modified: incubator/wookie/trunk/WebContent/WEB-INF/dwr.xml
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/WebContent/WEB-INF/dwr.xml?rev=1238088&r1=1238087&r2=1238088&view=diff
==============================================================================
--- incubator/wookie/trunk/WebContent/WEB-INF/dwr.xml (original)
+++ incubator/wookie/trunk/WebContent/WEB-INF/dwr.xml Mon Jan 30 23:39:57 2012
@@ -32,6 +32,8 @@
       <include method="authenticate"/>
       <include method="updateToken"/>
       <include method="queryToken"/>
+      <include method="invalidateToken"/>
+      <include method="getClientId"/>
     </create>
         
     <convert converter="object" 
match="org.apache.wookie.ajaxmodel.impl.PreferenceDelegate" 
javascript="Preference">

Modified: incubator/wookie/trunk/features/oauth/oauth.js
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/features/oauth/oauth.js?rev=1238088&r1=1238087&r2=1238088&view=diff
==============================================================================
--- incubator/wookie/trunk/features/oauth/oauth.js (original)
+++ incubator/wookie/trunk/features/oauth/oauth.js Mon Jan 30 23:39:57 2012
@@ -30,21 +30,27 @@ oAuth = new function OAuth() {
                                        }, async: false});
                        window.close();
                }
-               
-               OAuthConnector.queryToken(widget.instanceid_key, {
-                       callback: function(token_info) {
-                               if (token_info != "invalid") {
-                                       oAuth.access_token = token_info;
-                                       oAuth.client_id = widget.instanceid_key;
-                                       oAuth.status = "A";
-                               } else { 
-                                       oAuth.status = "O";                     
-                               }                                               
                        
-                       }, async:false});
+               dwr.engine.beginBatch();
+               OAuthConnector.getClientId(widget.instanceid_key, 
this.setClientId);
+               OAuthConnector.queryToken(widget.instanceid_key, 
this.setAccessToken);
+               dwr.engine.endBatch({async: false});
+       }
+       
+       this.setClientId = function(returned_client_id) {
+               oAuth.client_id = returned_client_id;
+       }
+       
+       this.setAccessToken = function(token_info) {
+               if (token_info != "invalid") {
+                       oAuth.access_token = token_info;
+                       oAuth.status = "A";
+               } else { 
+                       oAuth.status = "O";                     
+               }               
        }
        
        this.proxify = function(url) {
-               returnedUrl = widget.proxyUrl + "?instanceid_key=" + 
widget.instanceid_key + "&url=" + url;
+               returnedUrl = widget.getProxyUrl() + "?instanceid_key=" + 
widget.instanceid_key + "&url=" + url;
                if (oAuth.client_id != null && oAuth.access_token != null) {
                        returnedUrl = returnedUrl + "&client_id=" + 
oAuth.client_id + "&access_token=" + oAuth.access_token;
                }
@@ -59,6 +65,12 @@ oAuth = new function OAuth() {
                                }, async: false});
        }
        
+       this.invalidateToken = function() {
+               oAuth.status = "O";
+               oAuth.access_token = null;
+               OAuthConnector.invalidateToken(widget.instanceid_key);
+       }
+       
        this.showStatus = function(container_id) {
                if (oAuth.status == null || oAuth.status == "O") {
                        document.getElementById(container_id).innerHTML = "Not 
yet authenticated";
@@ -68,6 +80,7 @@ oAuth = new function OAuth() {
                        document.getElementById(container_id).innerHTML = 
"Authenticated";
                }
        }
+       
 }
 
 oAuth.init();

Added: incubator/wookie/trunk/scratchpad/widgets/fbfriend/build.xml
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/scratchpad/widgets/fbfriend/build.xml?rev=1238088&view=auto
==============================================================================
--- incubator/wookie/trunk/scratchpad/widgets/fbfriend/build.xml (added)
+++ incubator/wookie/trunk/scratchpad/widgets/fbfriend/build.xml Mon Jan 30 
23:39:57 2012
@@ -0,0 +1,23 @@
+<?xml version="1.0"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<project default="build-widget" basedir="." name="widget build file">
+       <property name="wookie.widgets.dir" location="../"/>
+       <property name="widget.shortname" value="fbfriend"/>
+       
+       <import file="../build.xml"/>
+</project>
\ No newline at end of file

Added: incubator/wookie/trunk/scratchpad/widgets/fbfriend/config.xml
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/scratchpad/widgets/fbfriend/config.xml?rev=1238088&view=auto
==============================================================================
--- incubator/wookie/trunk/scratchpad/widgets/fbfriend/config.xml (added)
+++ incubator/wookie/trunk/scratchpad/widgets/fbfriend/config.xml Mon Jan 30 
23:39:57 2012
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<widget xmlns="http://www.w3.org/ns/widgets"; 
id="http://infosec.fundp.ac.be/widgets/fbfriend"; version="0.1" width="300" 
height="450">  
+  <name>Facebook Friend</name>  
+  <description>Sample widget accessing Facebook graph API with oAuth 
support</description>  
+  <content src="index.html"/>  
+  <icon src="images/icon.png"/>  
+  <author>FUNDP</author>  
+  <licence>Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license agreements. See the NOTICE file distributed with this work 
for additional information regarding copyright ownership. The ASF licenses this 
file to You under the Apache License, Version 2.0 (the "License"); you may not 
use this file except in compliance with the License. You may obtain a copy of 
the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 
applicable law or agreed to in writing, software distributed under the License 
is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
KIND, either express or implied. See the License for the specific language 
governing permissions and limitations under the License.</licence>
+  <feature name="http://oauth.net/2"; required="true">
+       <param name="clientId" value="127514470636823"/>
+       <param name="authzServer" value="https://www.facebook.com/dialog/oauth"; 
/>
+       <param name="scope" value="publish_stream"/>
+  </feature>
+  <access origin="https://www.facebook.com:443"/>
+  <access origin="https://graph.facebook.com:443"/>  
+</widget>

Added: incubator/wookie/trunk/scratchpad/widgets/fbfriend/index.html
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/scratchpad/widgets/fbfriend/index.html?rev=1238088&view=auto
==============================================================================
--- incubator/wookie/trunk/scratchpad/widgets/fbfriend/index.html (added)
+++ incubator/wookie/trunk/scratchpad/widgets/fbfriend/index.html Mon Jan 30 
23:39:57 2012
@@ -0,0 +1,56 @@
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
+<html xmlns="http://www.w3.org/1999/xhtml";>
+       <head>
+        <meta http-equiv="pragma" content="no-cache"/>
+        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+        <link rel="stylesheet" type="text/css" href="style/screen.css" />
+        <script type="text/javascript" src="scripts/main.js" 
charset="utf-8"></script>
+        <script type="text/javascript" 
src="http://code.jquery.com/jquery-1.6.2.min.js";></script>
+               <title>oAuth</title>
+       </head>
+       <body>
+      <script type="text/javascript">
+      $(document).ready(function() {
+       if (window.oauth.status == "A") {
+               document.getElementById("button-login").value = "Disconnect";
+       }
+               window.oauth.showStatus("wookie-footer");
+      });
+      </script>        
+         <div id="wookie-widget">
+               <div id="wookie-toolbar">Greeting your Facebook friends</div>
+               <div id="wookie-settings">
+             <p>
+                     <input type="submit" class="wookie-form-button" 
value="Show friends" 
onclick="getFirstFriendList('https://graph.facebook.com/me/friends')"/>
+                     <input type="submit" class="wookie-form-button" 
id="button-login" value="Connect" onclick="logInOut()"/> 
+             </p>
+           </div>
+               <div id="wookie-content">
+               </div>
+           <div id="notices"></div>
+               <div id="wookie-footer"></div>
+         </div>
+         
+         
+       </body>
+<!-- fix forIE cashing - must go here even though its in the wrong place
+<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
+</HEAD>
+-->
+</html>
\ No newline at end of file

Added: incubator/wookie/trunk/scratchpad/widgets/fbfriend/scripts/main.js
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/scratchpad/widgets/fbfriend/scripts/main.js?rev=1238088&view=auto
==============================================================================
--- incubator/wookie/trunk/scratchpad/widgets/fbfriend/scripts/main.js (added)
+++ incubator/wookie/trunk/scratchpad/widgets/fbfriend/scripts/main.js Mon Jan 
30 23:39:57 2012
@@ -0,0 +1,133 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+var reqNr = 0;
+var myXHR = new XMLHttpRequest();
+
+function getFirstFriendList(jsonrpc_url) {
+    if (window.oauth && typeof window.oauth.proxify == 'function'){
+        jsonrpc_url = window.oauth.proxify(jsonrpc_url);
+    }
+    jsonrpc_url = jsonrpc_url + '&limit=5';
+        
+       myXHR.open('GET', jsonrpc_url, true);
+       myXHR.setRequestHeader('Content-Type', 'application/json');
+       myXHR.onreadystatechange = handleFindFriend;
+       myXHR.send();
+}
+
+function getNextFriendList(jsonrpc_url) {
+    if (typeof window.widget.proxify == 'function'){
+        jsonrpc_url = window.widget.proxify(jsonrpc_url);
+    }
+       myXHR.open('GET', jsonrpc_url, true);
+       myXHR.setRequestHeader('Content-Type', 'application/json');
+       myXHR.onreadystatechange = handleFindFriend;
+       myXHR.send();
+}
+
+function logInOut() {
+       if (window.oauth){
+               if (window.oauth.status == "A") {
+                       if (typeof window.oauth.invalidateToken == 'function') {
+                               window.oauth.invalidateToken();
+                               document.getElementById("button-login").value = 
"Connect";
+                               
document.getElementById('wookie-content').innerHTML = "";
+                       }
+               } else {
+                       if (typeof window.oauth.authenticate == 'function') {
+                               window.oauth.authenticate();
+                               if (window.oauth.status == "A") {
+                                       
document.getElementById('button-login').value = 'Disconnect';
+                                       
document.getElementById('wookie-content').innerHTML = "";
+                               }
+                       }
+               }
+               window.oauth.showStatus("wookie-footer");
+       }
+}
+
+function writeToWall(user_id) {
+       var jsonrpc_url = 'https://graph.facebook.com/' + user_id + '/feed';
+    if (window.oauth && typeof window.oauth.proxify == 'function'){
+        jsonrpc_url = window.oauth.proxify(jsonrpc_url);
+    }
+    jsonrpc_url = jsonrpc_url + '&message=' + 
escape(document.getElementById('msg_' + user_id).value);
+    var user_message = document.getElementById('msg_' + user_id).value;
+    if (user_message.length == 0) {
+       notify('Please write something to send');
+       document.getElementById('msg_' + user_id).focus();
+       return;
+    }
+       myXHR.open('POST', jsonrpc_url, true);
+       myXHR.setRequestHeader('Content-Type', 'application/json');
+       myXHR.onreadystatechange = handleWriteToWall;
+       myXHR.send();
+}
+
+function handleWriteToWall(evtXHR) {
+       if (myXHR.readyState == 4){
+               if (myXHR.status == 200) {
+                       result = JSON.parse(myXHR.responseText);
+                       if (typeof result.error  != 'undefined') {
+                               notify('Widget instance has not enough 
authorization to write on wall');
+                       } else {
+                               notify('Wall message is succesfully posted');
+                       }
+               }
+       }
+}
+
+function handleFindFriend(evtXHR) {
+       if (myXHR.readyState == 4){
+               if (myXHR.status == 200) {
+                       result = JSON.parse(myXHR.responseText);
+                       friendList = '<p>';
+                       if (typeof result.data  == 'undefined') {
+                               notify('Something goes wrong');
+                       } else {
+                               if (typeof result.paging.previous != 
'undefined') {
+                                       friendList = '<input type="submit" 
class="wookie-form-button" value="Prev" onclick="getNextFriendList(\'' + 
result.paging.previous + '\')"/>';
+                               }
+                               if (typeof result.paging.next != 'undefined') {
+                                       friendList = friendList + '<input 
type="submit" class="wookie-form-button" value="Next" 
onclick="getNextFriendList(\'' + result.paging.next + '\')"/>';
+                               }
+                               friendList = friendList + '</p> Write a message 
to wall of your friends <table>';
+                               for (i=0; i<result.data.length; i++) {
+                                       friendPhoto = '<img 
src="http://graph.facebook.com/' + result.data[i].id + '/picture" alt="friend 
avatar" height="42" width="42" />';
+                                       friendName  = result.data[i].name 
+                                                               + '<br/> <input 
type="text" id="msg_' + result.data[i].id + '" value=""/>'
+                                                               + '<input 
type="submit" class="wookie-form-button" value="OK" onclick="writeToWall(\'' + 
result.data[i].id + '\')"/>' ;
+                                       friendList = friendList + '<tr><td>' + 
friendPhoto + '</td><td>' + friendName + '</td></tr>';
+                               }
+                               friendList = friendList + '</table>';
+                               
document.getElementById('wookie-content').innerHTML = '<p>' + friendList + 
'</p>';
+                       }
+
+               } else {
+                       notify("Invocation Errors Occured. Status: " + 
myXHR.status);
+               }
+       }
+}
+
+function notify(message){
+       if (window.widget && widget.showNotification){
+               widget.showNotification(message, function(){widget.show()});
+       } else {
+               document.getElementById('notices').innerHTML = 
"<p>"+message+"</p>";
+       }
+       if (message.length > 0) setTimeout ("notify('')", 3000);
+}
\ No newline at end of file

Added: incubator/wookie/trunk/scratchpad/widgets/fbfriend/style/screen.css
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/scratchpad/widgets/fbfriend/style/screen.css?rev=1238088&view=auto
==============================================================================
--- incubator/wookie/trunk/scratchpad/widgets/fbfriend/style/screen.css (added)
+++ incubator/wookie/trunk/scratchpad/widgets/fbfriend/style/screen.css Mon Jan 
30 23:39:57 2012
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+html, body {
+  height:100%; 
+  max-height:100%; 
+  padding:0; 
+  margin:0; 
+  border:0; 
+  font-family: "trebuchet ms", tahoma, verdana, arial, sans-serif;
+  /* hide overflow:hidden from IE5/Mac */ 
+  /* \*/ 
+  overflow: hidden; 
+  /* */ 
+}
+
+#wookie-widget {
+       min-height:100%;
+    position:relative;
+}
+
+#wookie-toolbar {
+       background-color:#C0C0C0;
+    text-align:center;
+    font-size:75%;
+    height:16px;
+}
+
+#wookie-widget-icon {
+       float:left;
+}
+
+#wookie-content {
+       padding-top:5px;
+       padding-left:5px;
+    font-size:12px;
+}
+
+#wookie-settings {
+       display:block;
+}
+
+#notices {
+    width:100%;
+    font-size:75%;
+    text-align:left;
+    color:red;
+}
+
+#wookie-footer {
+       background-color:#C0C0C0;
+       position:absolute;
+    bottom:0;
+    width:100%;
+    font-size:75%;
+    text-align:center;
+    height:1.5em;   /* Height of the footer */
+}
+
+input.wookie-form-button {
+   font-size:9px;
+   font-family:Verdana,sans-serif;
+   font-weight:bold;
+   color:#fcfcfc;
+   background-color:#000000;
+   border-style:solid;
+   border-color:#cccccc;
+   border-width:1px;
+}
\ No newline at end of file

Propchange: incubator/wookie/trunk/scratchpad/widgets/fbfriend/style/screen.css
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/wookie/trunk/scratchpad/widgets/fbfriend/style/screen.css
------------------------------------------------------------------------------
    svn:executable = *

Modified: 
incubator/wookie/trunk/src/org/apache/wookie/feature/oauth/oAuthClient.java
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/feature/oauth/oAuthClient.java?rev=1238088&r1=1238087&r2=1238088&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/feature/oauth/oAuthClient.java 
(original)
+++ incubator/wookie/trunk/src/org/apache/wookie/feature/oauth/oAuthClient.java 
Mon Jan 30 23:39:57 2012
@@ -31,15 +31,32 @@ import org.apache.wookie.beans.IStartFil
 import org.apache.wookie.beans.IWidgetInstance;
 import org.apache.wookie.beans.util.IPersistenceManager;
 import org.apache.wookie.beans.util.PersistenceManagerFactory;
+import org.apache.wookie.feature.IFeature;
 import org.apache.wookie.server.LocaleHandler;
 import org.directwebremoting.WebContextFactory;
 
-public class oAuthClient {
+public class oAuthClient implements IFeature {
 
-  public String getName() {
+       public String getName() {
                return "http://oauth.net/2";;
        }
        
+       public String[] scripts() {
+               return new String[] {"/wookie/dwr/interface/OAuthConnector.js", 
"/wookie/shared/js/oauth.js"};
+       }
+
+       public String[] stylesheets() {
+               return null;
+       }
+
+       public boolean flattenOnExport() {
+               return false;
+       }
+
+       public String getFolder() {
+               return null;
+       }
+       
        public String authenticate(String idKey_RedirectUri) {
                int iPos = idKey_RedirectUri.indexOf('#');
                String idKey = idKey_RedirectUri.substring(0, iPos);
@@ -83,9 +100,22 @@ public class oAuthClient {
                Collection<IParam> oAuthParams = oAuthFeature.getParameters();
                String clientId = idKey;
                String authzServer = null;
+               String scope = ""; 
                for (IParam aParam : oAuthParams) {
-                       if ("authzServer".equals(aParam.getParameterName())) {
-                               authzServer = aParam.getParameterValue();
+                       String paramName = 
aParam.getParameterName().toLowerCase();
+                       String paramValue = aParam.getParameterValue();
+                       if ("authzserver".equals(paramName)) {
+                               authzServer = paramValue;
+                       } else if ("clientid".equals(paramName)) {
+                               if (!"auto".equalsIgnoreCase(paramValue)) {
+                                       clientId = paramValue;
+                               }
+                       } else if ("scope".equals(aParam.getParameterName())) {
+                               scope = paramValue;
+                       } else if ("redirecturi".equals(paramName)) {
+                               if (paramValue.length() != 0 && 
!"auto".equalsIgnoreCase(paramValue)) {
+                                       redirectUri = paramValue;
+                               }
                        }
                }
                
@@ -94,7 +124,11 @@ public class oAuthClient {
                        persistenceManager.delete(oauthToken);
                }
                
-               String url = authzServer + "?client_id=" + clientId + 
"&response_type=code&redirect_uri=" + redirectUri; 
+               String url = authzServer + "?client_id=" + clientId + 
"&response_type=token&redirect_uri=" + redirectUri; 
+               
+               if (scope.length() > 0) {
+                       url = url + "&scope=" + scope;
+               }
                
                return url;
        }
@@ -112,7 +146,32 @@ public class oAuthClient {
                }
                return "invalid";
        }
+       
+       public void invalidateToken(String idKey) {
+               if(idKey == null) return;
+               IPersistenceManager persistenceManager = 
PersistenceManagerFactory.getPersistenceManager();
+               IWidgetInstance widgetInstance = 
persistenceManager.findWidgetInstanceByIdKey(idKey);
+               if(widgetInstance==null) return;
                
+               IOAuthToken oauthToken = 
persistenceManager.findOAuthToken(widgetInstance);
+               if (oauthToken != null) {
+                       persistenceManager.delete(oauthToken);
+               }
+       }
+       
+       public String getClientId(String idKey) {
+               if(idKey == null) return "invalid";
+               IPersistenceManager persistenceManager = 
PersistenceManagerFactory.getPersistenceManager();
+               IWidgetInstance widgetInstance = 
persistenceManager.findWidgetInstanceByIdKey(idKey);
+               if(widgetInstance==null) return "invalid";
+               IOAuthToken oauthToken = 
persistenceManager.findOAuthToken(widgetInstance);
+               if (oauthToken != null) {
+                       return oauthToken.getClientId();
+               } else {
+                       return "invalid";
+               }
+       }
+       
        public String updateToken(String idKey_tokenBunch) {
                int iPos = idKey_tokenBunch.indexOf('#');
                String idKey = idKey_tokenBunch.substring(0, iPos);
@@ -182,5 +241,4 @@ public class oAuthClient {
                }
                return oAuthParamMap;
        }
-
 }
\ No newline at end of file


Reply via email to