auth.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * Original:
  6. * @author Frank Karlitschek
  7. * @copyright 2010 Frank Karlitschek karlitschek@kde.org
  8. *
  9. * Adapted:
  10. * @author Michiel de Jong, 2012
  11. *
  12. * This library is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  14. * License as published by the Free Software Foundation; either
  15. * version 3 of the License, or any later version.
  16. *
  17. * This library is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public
  23. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. // Do not load FS ...
  27. $RUNTIME_NOSETUPFS = true;
  28. OCP\App::checkAppEnabled('remoteStorage');
  29. require_once('Sabre/autoload.php');
  30. require_once('lib_remoteStorage.php');
  31. require_once('oauth_ro_auth.php');
  32. ini_set('default_charset', 'UTF-8');
  33. #ini_set('error_reporting', '');
  34. @ob_clean();
  35. foreach($_GET as $k => $v) {
  36. if($k=='userid'){
  37. $userId=$v;
  38. } else if($k=='redirect_uri'){
  39. $appUrlParts=explode('/', $v);
  40. $appUrl = $appUrlParts[2];//bit dodgy i guess
  41. } else if($k=='scope'){
  42. $categories=$v;
  43. }
  44. }
  45. $currUser = OCP\USER::getUser();
  46. if($userId && $appUrl && $categories) {
  47. if($currUser == $userId) {
  48. if(isset($_POST['allow'])) {
  49. //TODO: check if this can be faked by editing the cookie in firebug!
  50. $token=OC_remoteStorage::createCategories($appUrl, $categories);
  51. header('Location: '.$_GET['redirect_uri'].'#access_token='.$token.'&token_type=bearer');
  52. } else if($existingToken = OC_remoteStorage::getTokenFor($appUrl, $categories)) {
  53. header('Location: '.$_GET['redirect_uri'].'#access_token='.$existingToken.'&token_type=bearer');
  54. } else {
  55. //params ok, logged in ok, but need to click Allow still:
  56. ?>
  57. <!DOCTYPE html>
  58. <html>
  59. <head>
  60. <title>ownCloud</title>
  61. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  62. <link rel="shortcut icon" href="../../../core/img/favicon.png" /><link rel="apple-touch-icon-precomposed" href="../../../core/img/favicon-touch.png" />
  63. <link rel="stylesheet" href="../../../core/css/styles.css" type="text/css" media="screen" />
  64. <link rel="stylesheet" href="../../../core/css/auth.css" type="text/css" media="screen" />
  65. </head>
  66. <body id="body-login">
  67. <div id="login">
  68. <header>
  69. <div id="header">
  70. <img src="../../../core/img/logo.png" alt="ownCloud" />
  71. </div>
  72. </header>
  73. <section id="main">
  74. <div id="oauth">
  75. <h2><img src="../../../core/img/remoteStorage-big.png" alt="remoteStorage" /></h2>
  76. <p><strong><?php $appUrlParts = explode('/', $_GET['redirect_uri']); echo htmlentities($appUrlParts[2]); ?></strong>
  77. requests read &amp; write access to your
  78. <?php
  79. $categories = explode(',', htmlentities($_GET['scope']));
  80. if(!count($categories)) {
  81. echo htmlentities($_GET['scope']);
  82. } else {
  83. echo '<em>'.$categories[0].'</em>';
  84. if(count($categories)==2) {
  85. echo ' and <em>'.$categories[1].'</em>';
  86. } else if(count($categories)>2) {
  87. for($i=1; $i<count($categories)-1; $i++) {
  88. echo ', <em>'.$categories[$i].'</em>';
  89. }
  90. echo ', and <em>'.$categories[$i].'</em>';
  91. }
  92. }
  93. ?>.
  94. </p>
  95. <form accept-charset="UTF-8" method="post">
  96. <input id="allow-auth" name="allow" type="submit" value="Allow" />
  97. <input id="deny-auth" name="deny" type="submit" value="Deny" />
  98. </form>
  99. </div>
  100. </section>
  101. </div>
  102. <footer><p class="info"><a href="http://owncloud.org/">ownCloud</a> &ndash; web services under your control</p></footer>
  103. </body>
  104. </html>
  105. <?php
  106. }//end 'need to click Allow still'
  107. } else {//login not ok
  108. if($currUser) {
  109. die('You are logged in as '.$currUser.' instead of '.$userId);
  110. } else {
  111. header('Location: /?redirect_url='.urlencode('/apps/remoteStorage/auth.php'.$_SERVER['PATH_INFO'].'?'.$_SERVER['QUERY_STRING']));
  112. }
  113. }
  114. } else {//params not ok
  115. die('please use e.g. /?app=remoteStorage&getfile=auth.php&userid=admin&redirect_uri=http://host/path&scope=...');
  116. }