diff options
| author | Christian Weiske <cweiske@cweiske.de> | 2014-09-29 21:42:55 +0200 |
|---|---|---|
| committer | Christian Weiske <cweiske@cweiske.de> | 2014-09-29 21:42:55 +0200 |
| commit | 35be0ae011c70e766417b1e640a8dac03644a3b6 (patch) | |
| tree | a1a19eaa48fc1f1b60bee373ffb4c54dfb173c31 /controller | |
| parent | 01aae57048be789c8102106833f734b382aafc2e (diff) | |
| download | grauphel-35be0ae011c70e766417b1e640a8dac03644a3b6.tar.gz grauphel-35be0ae011c70e766417b1e640a8dac03644a3b6.zip | |
Show client name in oauth authorization (works for tomdroid only)
Diffstat (limited to 'controller')
| -rw-r--r-- | controller/apicontroller.php | 31 | ||||
| -rw-r--r-- | controller/oauthcontroller.php | 6 |
2 files changed, 37 insertions, 0 deletions
diff --git a/controller/apicontroller.php b/controller/apicontroller.php index 691d8ab..ee16f80 100644 --- a/controller/apicontroller.php +++ b/controller/apicontroller.php @@ -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) * diff --git a/controller/oauthcontroller.php b/controller/oauthcontroller.php index 8672927..6ab17d2 100644 --- a/controller/oauthcontroller.php +++ b/controller/oauthcontroller.php @@ -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' ), |
