Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default client ids for desktop and mobile clients #38

Merged
merged 1 commit into from
May 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions appinfo/Migrations/Version20170329194544.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
namespace OCA\oauth2\Migrations;

use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use OCA\OAuth2\Db\Client;
use OCA\OAuth2\Db\ClientMapper;
use OCP\Migration\ISimpleMigration;
use OCP\Migration\IOutput;

/**
* This adds the default client ids for ownCloud mobile and desktop clients
*/
class Version20170329194544 implements ISimpleMigration {

private static $registry = [
['Desktop Client', 'http://localhost:*', 'xdXOt13JKxym1B1QcEncf2XDkLAexMBFwiT9j6EfhhHFJhs2KM9jbjTmf8JBXE69', 'UBntmLjC2yYCeHwsyj73Uwo9TAaecAetRwMw0xYcvNL9yRdLSUi0hUAHfvCHFeFh'],
['Android', 'oc://android.owncloud.com', 'e4rAsNUSIUs0lF4nbv9FmCeUkTlV9GdgTLDH1b5uie7syb90SzEVrbN7HIpmWJeD', 'dInFYGV33xKzhbRmpqQltYNdfLdJIfJ9L5ISoKhNoT9qZftpdWSP71VrpGR9pmoD'],

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oc:// is actually a very short name. It it not true that these need to be globally registered on the whole phone?
Would it not be better to have something longer such as owncloud:// or even owncloudauth:// ?

Also, can two different owncloud client co-exist on the same phone? (say, a branded client, the original owncloud client, and the nextcloud client)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good points, but only relevant for the current POC in Android. For the final implementation we will not register the callback globally and will not use an external web browser. Everything will happen in a WebView owned by the app, and only it will monitor the URLs loaded.

I like owncloud:// , that's what we used originally; oc:// was just more handy :)

// ['iOS', '???', 'mxd5OQDk6es5LzOzRvidJNfXLUZS2oN3oUFeXPP8LpPrhx3UroJFduGEYIBOxkY1', 'KFeFWWEZO9TkisIQzR3fo7hfiMXlOpaqP8CFuTbSHzV1TUuGECglPxpiVKJfOXIx']
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use oc://ios.owncloud.com as callback URL for the iOS client? The old iOS code is not testable right now, but the URI should work anyway.

];
/**
* @param IOutput $out
*/
public function run(IOutput $out) {
foreach(self::$registry as list($name, $redirectUrl, $clientId, $secret)) {
try {
$this->addClient($name, $redirectUrl, $clientId, $secret);

$out->info("The client <$name> has been added.");
} catch (UniqueConstraintViolationException $ex) {
$out->info("The client <$name> already known.");
}
}
}

/**
* @param string $name
* @param string $redirectUrl
* @param string $clientId
* @param string $secret
*/
protected function addClient($name, $redirectUrl, $clientId, $secret) {
/** @var ClientMapper $mapper */
$mapper = \OC::$server->query(ClientMapper::class);

$client = new Client();
$client->setIdentifier($clientId);
$client->setSecret($secret);
$client->setRedirectUri($redirectUrl);
$client->setName($name);
$client->setAllowSubdomains(false);

$mapper->insert($client);
}
}
8 changes: 8 additions & 0 deletions appinfo/database.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@
<default>false</default>
<notnull>true</notnull>
</field>
<index>
<name>name_idx</name>
<unique>true</unique>
<field>
<name>name</name>
<sorting>ascending</sorting>
</field>
</index>
</declaration>
</table>
<table>
Expand Down
4 changes: 2 additions & 2 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<description>Application for using OAuth 2.0 in ownCloud</description>
<licence>AGPL</licence>
<author>Project Seminar "sciebo@Learnweb" of the University of Münster</author>
<version>0.1.0</version>
<version>0.1.1</version>
<namespace>OAuth2</namespace>
<category>other</category>
<category>integration</category>
<dependencies>
<owncloud min-version="9.1" max-version="10"/>
</dependencies>
Expand Down