Show client name in oauth authorization (works for tomdroid only)
authorChristian Weiske <cweiske@cweiske.de>
Mon, 29 Sep 2014 19:42:55 +0000 (21:42 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Mon, 29 Sep 2014 19:42:55 +0000 (21:42 +0200)
controller/apicontroller.php
controller/oauthcontroller.php
grauphel.css
templates/oauthAuthorize.php

index 691d8abbe0cdaf99b3586c922c31194f2a2fc460..ee16f801f8e77570fe4abd0a596a615e4c990e44 100644 (file)
@@ -105,6 +105,12 @@ class ApiController extends Controller
             'api-version' => '1.0',
         );
 
+        $client = $this->getClient();
+        if ($client !== false) {
+            $data['oauth_authorize_url'] .= '?client='
+                . urlencode($this->getNiceClientName($client));
+        }
+
         if ($authenticated) {
             $data['user-ref'] = array(
                 'api-ref' => $urlGen->getAbsoluteURL(
@@ -327,6 +333,31 @@ class ApiController extends Controller
         return new JSONResponse($note);
     }
 
+    protected function getClient()
+    {
+        if (isset($_SERVER['HTTP_X_TOMBOY_CLIENT'])) {
+            $client = $_SERVER['HTTP_X_TOMBOY_CLIENT'];
+            $doublepos = strpos($client, ', org.tomdroid');
+            if ($doublepos !== false) {
+                //https://bugs.launchpad.net/tomdroid/+bug/1375436
+                //X-Tomboy-Client header is sent twice
+                $client = substr($client, 0, $doublepos);
+            }
+            return $client;
+        }
+
+        return false;
+    }
+
+    protected function getNiceClientName($client)
+    {
+        if (substr($client, 0, 12) == 'org.tomdroid') {
+            //org.tomdroid v0.7.5, build 14, Android v4.4.2, innotek GmbH/VirtualBox
+            return 'Tomdroid';
+        }
+        return $client;
+    }
+
     /**
      * Checks if the given user is authorized (by oauth token or normal login)
      *
index 8672927ecb584f78740c34dce3497febe1eff85d..6ab17d224f64dfeae05b5ff11ce2e23a28910b0c 100644 (file)
@@ -118,10 +118,16 @@ class OauthController extends Controller
             return $token;
         }
 
+        $client = 'unknown';
+        if (isset($_GET['client'])) {
+            $client = $_GET['client'];
+        }
+
         $res = new TemplateResponse('grauphel', 'oauthAuthorize');
         $res->setParams(
             array(
                 'oauth_token' => $token->tokenKey,
+                'client'      => $client,
                 'formaction'  => $this->deps->urlGen->linkToRoute(
                     'grauphel.oauth.confirm'
                 ),
index 37360db1815c7a9328ed527e302b90098367a23a..e31ed6d5a577a33c425b9aa95b700e76d466df8d 100644 (file)
 .app-grauphel #app-content a.lined {
     text-decoration: underline;
 }
+
+.app-grauphel .oauth-authorize {
+    margin: 2ex;
+    text-align: center;
+}
+.app-grauphel .msg {
+    padding: 2ex;
+}
+.app-grauphel .buttons {
+    margin-top: 2ex;
+    text-align: center;
+}
\ No newline at end of file
index 5d4023b33f1666c403b4a1d939391a5a56eda861..cab58ab6f6a7d3ab0324636c0970aa8de961644b 100644 (file)
@@ -1,9 +1,14 @@
-<form method="post" action="<?php p($_['formaction']); ?>">
+<link rel="stylesheet" href="<?php p(OCP\Util::linkTo('grauphel','grauphel.css')); ?>" type="text/css"/>
+<form method="post" action="<?php p($_['formaction']); ?>" class="oauth-authorize">
  <input type="hidden" value="<?php p($_['requesttoken']); ?>" name="requesttoken" />
  <input type="hidden" value="<?php p($_['oauth_token']); ?>" name="oauth_token" />
- <p>
-  Shall application FIXME get full access to the notes?
+ <p class="msg">
+  Shall application
+  <strong><?php p($_['client']); ?></strong>
+  get full access to the notes?
  </p>
- <button type="submit" name="auth" value="ok">Yes, authorize</button>
- <button type="submit" name="auth" value="cancel">No, decline</button>
+ <div class="buttons">
+  <button type="submit" name="auth" value="ok">Yes, authorize</button>
+  <button type="submit" name="auth" value="cancel">No, decline</button>
+ </div>
 </form>