From b06588ffa1c925d0a008a34bf8fa5c316b964b87 Mon Sep 17 00:00:00 2001 From: Fabio Comuni Date: Thu, 20 Oct 2011 15:57:35 +0200 Subject: Initial work adding oauth to api --- include/api.php | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'include/api.php') diff --git a/include/api.php b/include/api.php index 1334d8eae..252caeb8e 100644 --- a/include/api.php +++ b/include/api.php @@ -2,7 +2,7 @@ require_once("bbcode.php"); require_once("datetime.php"); require_once("conversation.php"); - + require_once("oauth.php"); /* * Twitter-Like API * @@ -1135,3 +1135,32 @@ } api_register_func('api/direct_messages/sent','api_direct_messages_sentbox',true); api_register_func('api/direct_messages','api_direct_messages_inbox',true); + + + + function api_oauth_request_token(&$a, $type){ + try{ + $oauth = new FKOAuth1(); + $r = $oauth->fetch_request_token(OAuthRequest::from_request()); + }catch(Exception $e){ + echo "error=". OAuthUtil::urlencode_rfc3986($e->getMessage()); killme(); + } + echo "oauth_token=".$r->key."&oauth_secret=".$r->secret; + killme(); + } + function api_oauth_access_token(&$a, $type){ + try{ + $oauth = new FKOAuth1(); + $r = $oauth->fetch_access_token(OAuthRequest::from_request()); + }catch(Exception $e){ + echo "error=". OAuthUtil::urlencode_rfc3986($e->getMessage()); killme(); + } + echo "oauth_token=".$r->key."&oauth_secret=".$r->secret; + killme(); + } + function api_oauth_authorize(&$a, $type){ + } + api_register_func('api/oauth/request_token', 'api_oauth_request_token', false); + api_register_func('api/oauth/access_token', 'api_oauth_access_token', false); + api_register_func('api/oauth/authorize', 'api_oauth_authorize', false); + -- cgit v1.2.3 From ff7fc68382bf1359adc31bd65bb6786b7f63e31a Mon Sep 17 00:00:00 2001 From: Fabio Comuni Date: Wed, 26 Oct 2011 17:15:36 +0200 Subject: oauthapi: authorize app --- include/api.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'include/api.php') diff --git a/include/api.php b/include/api.php index 252caeb8e..2de965681 100644 --- a/include/api.php +++ b/include/api.php @@ -1158,9 +1158,8 @@ echo "oauth_token=".$r->key."&oauth_secret=".$r->secret; killme(); } - function api_oauth_authorize(&$a, $type){ - } + api_register_func('api/oauth/request_token', 'api_oauth_request_token', false); api_register_func('api/oauth/access_token', 'api_oauth_access_token', false); - api_register_func('api/oauth/authorize', 'api_oauth_authorize', false); + -- cgit v1.2.3 From 41cbd84a74eff278787daf3c23582c49cf814236 Mon Sep 17 00:00:00 2001 From: Fabio Comuni Date: Mon, 7 Nov 2011 17:36:58 +0100 Subject: api: login with oauth --- include/api.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'include/api.php') diff --git a/include/api.php b/include/api.php index 2de965681..d8942bfff 100644 --- a/include/api.php +++ b/include/api.php @@ -27,6 +27,23 @@ * Simple HTTP Login */ function api_login(&$a){ + // login with oauth + try{ + $oauth = new FKOAuth1(); + list($consumer,$token) = $oauth->verify_request(OAuthRequest::from_request()); + if (!is_null($token)){ + $oauth->loginUser($token->uid); + call_hooks('logged_in', $a->user); + return; + } + echo __file__.__line__.__function__."
"; var_dump($consumer, $token); die();
+		}catch(Exception $e){
+			logger(__file__.__line__.__function__."\n".$e);
+			//die(__file__.__line__.__function__."
".$e); die();
+		}
+
+		
+		
 		// workaround for HTTP-auth in CGI mode
 		if(x($_SERVER,'REDIRECT_REMOTE_USER')) {
 		 	$userpass = base64_decode(substr($_SERVER["REDIRECT_REMOTE_USER"],6)) ;
@@ -1145,7 +1162,7 @@
 		}catch(Exception $e){
 			echo "error=". OAuthUtil::urlencode_rfc3986($e->getMessage()); killme();
 		}
-		echo "oauth_token=".$r->key."&oauth_secret=".$r->secret;
+		echo $r;
 		killme();	
 	}
 	function api_oauth_access_token(&$a, $type){
@@ -1155,7 +1172,7 @@
 		}catch(Exception $e){
 			echo "error=". OAuthUtil::urlencode_rfc3986($e->getMessage()); killme();
 		}
-		echo "oauth_token=".$r->key."&oauth_secret=".$r->secret;
+		echo $r;
 		killme();			
 	}
 
-- 
cgit v1.2.3