2012-07-31 17:34:45 +04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* ownCloud
|
|
|
|
*
|
2012-08-03 04:02:31 +04:00
|
|
|
* @author Tom Needham
|
|
|
|
* @author Michael Gapczynski
|
|
|
|
* @copyright 2012 Tom Needham tom@owncloud.com
|
|
|
|
* @copyright 2012 Michael Gapczynski mtgap@owncloud.com
|
2012-07-31 17:34:45 +04:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 3 of the License, or any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-08-03 04:02:31 +04:00
|
|
|
class OC_OAuthServer extends OAuthServer {
|
|
|
|
|
|
|
|
public function fetch_request_token(&$request) {
|
|
|
|
$this->get_version($request);
|
|
|
|
$consumer = $this->get_consumer($request);
|
|
|
|
$this->check_signature($request, $consumer, null);
|
|
|
|
$callback = $request->get_parameter('oauth_callback');
|
|
|
|
$scope = $request->get_parameter('scope');
|
|
|
|
// TODO Validate scopes
|
|
|
|
return $this->data_store->new_request_token($consumer, $scope, $callback);
|
2012-07-31 17:34:45 +04:00
|
|
|
}
|
|
|
|
|
2012-08-03 04:02:31 +04:00
|
|
|
public function authoriseRequestToken(&$request) {
|
|
|
|
$this->get_version($request);
|
|
|
|
$consumer = $this->get_consumer($request);
|
|
|
|
$this->check_signature($request, $consumer, null);
|
|
|
|
$token = $this->get_token($request, $consumer, 'request');
|
|
|
|
$this->check_signature($request, $consumer, $token);
|
|
|
|
return $this->data_store->authorise_request_token($token, $consumer, OC_User::getUser());
|
2012-07-31 17:34:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* checks if request is authorised
|
|
|
|
* TODO distinguish between failures as one is a 400 error and other is 401
|
|
|
|
* @return string|int
|
|
|
|
*/
|
2012-08-03 04:02:31 +04:00
|
|
|
public static function isAuthorised($scope) {
|
|
|
|
try {
|
|
|
|
$request = OAuthRequest::from_request();
|
|
|
|
$this->verify_request();
|
|
|
|
} catch (OAuthException $exception) {
|
2012-07-31 17:34:45 +04:00
|
|
|
return false;
|
|
|
|
}
|
2012-08-03 04:02:31 +04:00
|
|
|
// TODO Get user out of token? May have to write own verify_request()
|
|
|
|
// $run = true;
|
|
|
|
// OC_Hook::emit( "OC_User", "pre_login", array( "run" => &$run, "uid" => $user ));
|
|
|
|
// if(!$run){
|
|
|
|
// return false;
|
|
|
|
// }
|
|
|
|
// OC_User::setUserId($user);
|
|
|
|
// OC_Hook::emit( "OC_User", "post_login", array( "uid" => $user ));
|
|
|
|
// return $user;
|
2012-07-31 17:34:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|