diff options
Diffstat (limited to 'settings')
-rw-r--r-- | settings/css/oauth.css | 4 | ||||
-rw-r--r-- | settings/oauth.php | 98 | ||||
-rw-r--r-- | settings/templates/oauth-required-apps.php | 19 | ||||
-rw-r--r-- | settings/templates/oauth.php | 20 |
4 files changed, 141 insertions, 0 deletions
diff --git a/settings/css/oauth.css b/settings/css/oauth.css new file mode 100644 index 00000000000..ccdb98cfa39 --- /dev/null +++ b/settings/css/oauth.css @@ -0,0 +1,4 @@ +.guest-container{ width:35%; margin: 2em auto 0 auto; } +#oauth-request a.button{ float: right; } +#oauth-request ul li{ list-style: disc; } +#oauth-request ul { margin-left: 2em; margin-top: 1em; } diff --git a/settings/oauth.php b/settings/oauth.php new file mode 100644 index 00000000000..8dba9b33a53 --- /dev/null +++ b/settings/oauth.php @@ -0,0 +1,98 @@ +<?php +/** + * Copyright (c) 2012, Tom Needham <tom@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or later. + * See the COPYING-README file. + */ + +require_once('../lib/base.php'); +// Logic +$operation = isset($_GET['operation']) ? $_GET['operation'] : ''; +$server = OC_OAuth_server::init(); + +switch($operation){ + + case 'register': + + // Here external apps can register with an ownCloud + if(empty($_GET['name']) || empty($_GET['url'])){ + // Invalid request + echo 401; + } else { + $callbacksuccess = empty($_GET['callback_success']) ? null : $_GET['callback_success']; + $callbackfail = empty($_GET['callback_fail']) ? null : $_GET['callback_fail']; + $consumer = OC_OAuth_Server::register_consumer($_GET['name'], $_GET['url'], $callbacksuccess, $callbackfail); + + echo 'Registered consumer successfully! </br></br>Key: ' . $consumer->key . '</br>Secret: ' . $consumer->secret; + } + break; + + case 'request_token': + + try { + $request = OAuthRequest::from_request(); + $token = $server->get_request_token($request); + echo $token; + } catch (OAuthException $exception) { + OC_Log::write('OC_OAuth_Server', $exception->getMessage(), OC_LOG::ERROR); + echo $exception->getMessage(); + } + + break; + case 'authorise'; + + OC_API::checkLoggedIn(); + // Example + $consumer = array( + 'name' => 'Firefox Bookmark Sync', + 'scopes' => array('ookmarks'), + ); + + // Check that the scopes are real and installed + $apps = OC_App::getEnabledApps(); + $notfound = array(); + foreach($consumer['scopes'] as $requiredapp){ + // App scopes are in this format: app_$appname + $requiredapp = end(explode('_', $requiredapp)); + if(!in_array($requiredapp, $apps)){ + $notfound[] = $requiredapp; + } + } + if(!empty($notfound)){ + // We need more apps :( Show error + if(count($notfound)==1){ + $message = 'requires that you have an extra app installed on your ownCloud. Please contact your ownCloud administrator and ask them to install the app below.'; + } else { + $message = 'requires that you have some extra apps installed on your ownCloud. Please contract your ownCloud administrator and ask them to install the apps below.'; + } + $t = new OC_Template('settings', 'oauth-required-apps', 'guest'); + OC_Util::addStyle('settings', 'oauth'); + $t->assign('requiredapps', $notfound); + $t->assign('consumer', $consumer); + $t->assign('message', $message); + $t->printPage(); + } else { + $t = new OC_Template('settings', 'oauth', 'guest'); + OC_Util::addStyle('settings', 'oauth'); + $t->assign('consumer', $consumer); + $t->printPage(); + } + break; + + case 'access_token'; + try { + $request = OAuthRequest::from_request(); + $token = $server->fetch_access_token($request); + echo $token; + } catch (OAuthException $exception) { + OC_Log::write('OC_OAuth_Server', $exception->getMessage(), OC_LOG::ERROR); + echo $exception->getMessage(); + } + + break; + default: + // Something went wrong, we need an operation! + OC_Response::setStatus(400); + break; + +} diff --git a/settings/templates/oauth-required-apps.php b/settings/templates/oauth-required-apps.php new file mode 100644 index 00000000000..d4fce54c59c --- /dev/null +++ b/settings/templates/oauth-required-apps.php @@ -0,0 +1,19 @@ +<?php +/** + * Copyright (c) 2012, Tom Needham <tom@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or later. + * See the COPYING-README file. + */ +?> +<div id="oauth-request" class="guest-container"> + <p><strong><?php echo $_['consumer']['name'].'</strong> '.$_['message']; ?></p> + <ul> + <?php + // Foreach requested scope + foreach($_['requiredapps'] as $requiredapp){ + echo '<li>'.$requiredapp.'</li>'; + } + ?> + </ul> + <a href="<?php echo OC::$WEBROOT; ?>" id="back-home" class="button">Back to ownCloud</a> +</div> diff --git a/settings/templates/oauth.php b/settings/templates/oauth.php new file mode 100644 index 00000000000..053a8aee6d3 --- /dev/null +++ b/settings/templates/oauth.php @@ -0,0 +1,20 @@ +<?php +/** + * Copyright (c) 2012, Tom Needham <tom@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or later. + * See the COPYING-README file. + */ +?> +<div id="oauth-request" class="guest-container"> + <p><strong><?php echo $_['consumer']['name']; ?></strong> is requesting your permission to read, write, modify and delete data from the following apps:</p> + <ul> + <?php + // Foreach requested scope + foreach($_['consumer']['scopes'] as $app){ + echo '<li>'.$app.'</li>'; + } + ?> + </ul> + <a href="#" class="button">Allow</a> + <a href="#" class="button">Disallow</a> +</div> |