Merge pull request #10237 from annando/oauth-flow

Refine OAuth flow
This commit is contained in:
Hypolite Petovan 2021-05-13 11:27:30 -04:00 committed by GitHub
commit 1d44b97576
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 446 additions and 386 deletions

View File

@ -1,6 +1,6 @@
-- ------------------------------------------ -- ------------------------------------------
-- Friendica 2021.06-dev (Siberian Iris) -- Friendica 2021.06-dev (Siberian Iris)
-- DB_UPDATE_VERSION 1416 -- DB_UPDATE_VERSION 1417
-- ------------------------------------------ -- ------------------------------------------
@ -375,6 +375,9 @@ CREATE TABLE IF NOT EXISTS `application` (
`redirect_uri` varchar(255) NOT NULL COMMENT '', `redirect_uri` varchar(255) NOT NULL COMMENT '',
`website` varchar(255) COMMENT '', `website` varchar(255) COMMENT '',
`scopes` varchar(255) COMMENT '', `scopes` varchar(255) COMMENT '',
`read` boolean COMMENT 'Read scope',
`write` boolean COMMENT 'Write scope',
`follow` boolean COMMENT 'Follow scope',
PRIMARY KEY(`id`), PRIMARY KEY(`id`),
UNIQUE INDEX `client_id` (`client_id`) UNIQUE INDEX `client_id` (`client_id`)
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='OAuth application'; ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='OAuth application';
@ -387,7 +390,11 @@ CREATE TABLE IF NOT EXISTS `application-token` (
`uid` mediumint unsigned NOT NULL COMMENT 'Owner User id', `uid` mediumint unsigned NOT NULL COMMENT 'Owner User id',
`code` varchar(64) NOT NULL COMMENT '', `code` varchar(64) NOT NULL COMMENT '',
`access_token` varchar(64) NOT NULL COMMENT '', `access_token` varchar(64) NOT NULL COMMENT '',
`created_at` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'creation time', `created_at` datetime NOT NULL COMMENT 'creation time',
`scopes` varchar(255) COMMENT '',
`read` boolean COMMENT 'Read scope',
`write` boolean COMMENT 'Write scope',
`follow` boolean COMMENT 'Follow scope',
PRIMARY KEY(`application-id`,`uid`), PRIMARY KEY(`application-id`,`uid`),
INDEX `uid_id` (`uid`,`application-id`), INDEX `uid_id` (`uid`,`application-id`),
FOREIGN KEY (`application-id`) REFERENCES `application` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE, FOREIGN KEY (`application-id`) REFERENCES `application` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
@ -1500,6 +1507,28 @@ CREATE TABLE IF NOT EXISTS `workerqueue` (
INDEX `done_pid_priority_created` (`done`,`pid`,`priority`,`created`) INDEX `done_pid_priority_created` (`done`,`pid`,`priority`,`created`)
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Background tasks queue entries'; ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Background tasks queue entries';
--
-- VIEW application-view
--
DROP VIEW IF EXISTS `application-view`;
CREATE VIEW `application-view` AS SELECT
`application`.`id` AS `id`,
`application-token`.`uid` AS `uid`,
`application`.`name` AS `name`,
`application`.`redirect_uri` AS `redirect_uri`,
`application`.`website` AS `website`,
`application`.`client_id` AS `client_id`,
`application`.`client_secret` AS `client_secret`,
`application-token`.`code` AS `code`,
`application-token`.`access_token` AS `access_token`,
`application-token`.`created_at` AS `created_at`,
`application-token`.`scopes` AS `scopes`,
`application-token`.`read` AS `read`,
`application-token`.`write` AS `write`,
`application-token`.`follow` AS `follow`
FROM `application-token`
INNER JOIN `application` ON `application-token`.`application-id` = `application`.`id`;
-- --
-- VIEW post-user-view -- VIEW post-user-view
-- --

View File

@ -9,6 +9,21 @@ Friendica provides the following endpoints defined in [the official Mastodon API
Authentication is the same as described in [Using the APIs](help/api#Authentication). Authentication is the same as described in [Using the APIs](help/api#Authentication).
## Clients
Supported mobile apps:
- Tusky
- Husky
- twitlatte
Unsupported mobile apps:
- [Subway Tooter](https://github.com/tateisu/SubwayTooter) Uses the wrong grant_type when requesting a token, possibly a problem in the server type detection of the app. See issue https://github.com/tateisu/SubwayTooter/issues/156
- [Mammut](https://github.com/jamiesanson/Mammut) States that the instance doesn't exist. Most likely an issue in the vitality check of the app, see issue https://github.com/jamiesanson/Mammut/issues/19
- [AndStatus](https://github.com/andstatus/andstatus) Doesn't provide all data at token request, see issue https://github.com/andstatus/andstatus/issues/537
- [Fedilab](https://framagit.org/tom79/fedilab) Automatically uses the legacy API, see issue: https://framagit.org/tom79/fedilab/-/issues/520
## Entities ## Entities
These endpoints use the [Mastodon API entities](https://docs.joinmastodon.org/entities/). These endpoints use the [Mastodon API entities](https://docs.joinmastodon.org/entities/).

View File

@ -500,77 +500,26 @@ function settings_content(App $a)
} }
if (($a->argc > 1) && ($a->argv[1] === 'oauth')) { if (($a->argc > 1) && ($a->argv[1] === 'oauth')) {
if (($a->argc > 2) && ($a->argv[2] === 'add')) {
$tpl = Renderer::getMarkupTemplate('settings/oauth_edit.tpl');
$o .= Renderer::replaceMacros($tpl, [
'$form_security_token' => BaseModule::getFormSecurityToken("settings_oauth"),
'$title' => DI::l10n()->t('Add application'),
'$submit' => DI::l10n()->t('Save Settings'),
'$cancel' => DI::l10n()->t('Cancel'),
'$name' => ['name', DI::l10n()->t('Name'), '', ''],
'$key' => ['key', DI::l10n()->t('Consumer Key'), '', ''],
'$secret' => ['secret', DI::l10n()->t('Consumer Secret'), '', ''],
'$redirect' => ['redirect', DI::l10n()->t('Redirect'), '', ''],
'$icon' => ['icon', DI::l10n()->t('Icon url'), '', ''],
]);
return $o;
}
if (($a->argc > 3) && ($a->argv[2] === 'edit')) {
$r = q("SELECT * FROM clients WHERE client_id='%s' AND uid=%d",
DBA::escape($a->argv[3]),
local_user());
if (!DBA::isResult($r)) {
notice(DI::l10n()->t("You can't edit this application."));
return;
}
$app = $r[0];
$tpl = Renderer::getMarkupTemplate('settings/oauth_edit.tpl');
$o .= Renderer::replaceMacros($tpl, [
'$form_security_token' => BaseModule::getFormSecurityToken("settings_oauth"),
'$title' => DI::l10n()->t('Add application'),
'$submit' => DI::l10n()->t('Update'),
'$cancel' => DI::l10n()->t('Cancel'),
'$name' => ['name', DI::l10n()->t('Name'), $app['name'] , ''],
'$key' => ['key', DI::l10n()->t('Consumer Key'), $app['client_id'], ''],
'$secret' => ['secret', DI::l10n()->t('Consumer Secret'), $app['pw'], ''],
'$redirect' => ['redirect', DI::l10n()->t('Redirect'), $app['redirect_uri'], ''],
'$icon' => ['icon', DI::l10n()->t('Icon url'), $app['icon'], ''],
]);
return $o;
}
if (($a->argc > 3) && ($a->argv[2] === 'delete')) { if (($a->argc > 3) && ($a->argv[2] === 'delete')) {
BaseModule::checkFormSecurityTokenRedirectOnError('/settings/oauth', 'settings_oauth', 't'); BaseModule::checkFormSecurityTokenRedirectOnError('/settings/oauth', 'settings_oauth', 't');
DBA::delete('clients', ['client_id' => $a->argv[3], 'uid' => local_user()]); DBA::delete('application-token', ['application-id' => $a->argv[3], 'uid' => local_user()]);
DI::baseUrl()->redirect('settings/oauth/', true); DI::baseUrl()->redirect('settings/oauth/', true);
return; return;
} }
/// @TODO validate result with DBA::isResult() $applications = DBA::selectToArray('application-view', ['id', 'uid', 'name', 'website', 'scopes', 'created_at'], ['uid' => local_user()]);
$r = q("SELECT clients.*, tokens.id as oauth_token, (clients.uid=%d) AS my
FROM clients
LEFT JOIN tokens ON clients.client_id=tokens.client_id
WHERE clients.uid IN (%d, 0)",
local_user(),
local_user());
$tpl = Renderer::getMarkupTemplate('settings/oauth.tpl'); $tpl = Renderer::getMarkupTemplate('settings/oauth.tpl');
$o .= Renderer::replaceMacros($tpl, [ $o .= Renderer::replaceMacros($tpl, [
'$form_security_token' => BaseModule::getFormSecurityToken("settings_oauth"), '$form_security_token' => BaseModule::getFormSecurityToken("settings_oauth"),
'$baseurl' => DI::baseUrl()->get(true), '$baseurl' => DI::baseUrl()->get(true),
'$title' => DI::l10n()->t('Connected Apps'), '$title' => DI::l10n()->t('Connected Apps'),
'$add' => DI::l10n()->t('Add application'), '$name' => DI::l10n()->t('Name'),
'$edit' => DI::l10n()->t('Edit'), '$website' => DI::l10n()->t('Home Page'),
'$delete' => DI::l10n()->t('Delete'), '$created_at' => DI::l10n()->t('Created'),
'$consumerkey' => DI::l10n()->t('Client key starts with'), '$delete' => DI::l10n()->t('Remove authorization'),
'$noname' => DI::l10n()->t('No name'), '$apps' => $applications,
'$remove' => DI::l10n()->t('Remove authorization'),
'$apps' => $r,
]); ]);
return $o; return $o;
} }

View File

@ -37,7 +37,7 @@ class Card extends BaseFactory
*/ */
public function createFromUriId(int $uriId) public function createFromUriId(int $uriId)
{ {
$item = Post::selectFirst(['nody'], ['uri-id' => $uriId]); $item = Post::selectFirst(['body'], ['uri-id' => $uriId]);
if (!empty($item['body'])) { if (!empty($item['body'])) {
$data = BBCode::getAttachmentData($item['body']); $data = BBCode::getAttachmentData($item['body']);
} else { } else {

View File

@ -2914,11 +2914,11 @@ class Item
$data['description'] = ''; $data['description'] = '';
} }
if (!empty($data['author_name']) && !empty($data['provider_name'])) { if (($data['author_name'] ?? '') == ($data['provider_name'] ?? '')) {
$data['author_name'] = ''; $data['author_name'] = '';
} }
if (!empty($data['author_url']) && !empty($data['provider_url'])) { if (($data['author_url'] ?? '') == ($data['provider_url'] ?? '')) {
$data['author_url'] = ''; $data['author_url'] = '';
} }
} elseif (preg_match("/.*(\[attachment.*?\].*?\[\/attachment\]).*/ism", $body, $match)) { } elseif (preg_match("/.*(\[attachment.*?\].*?\[\/attachment\]).*/ism", $body, $match)) {

View File

@ -25,6 +25,7 @@ use Friendica\Core\System;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Module\BaseApi; use Friendica\Module\BaseApi;
use Friendica\Util\Network;
/** /**
* Apps class to register new OAuth clients * Apps class to register new OAuth clients
@ -37,9 +38,20 @@ class Apps extends BaseApi
*/ */
public static function post(array $parameters = []) public static function post(array $parameters = [])
{ {
// Workaround for AndStatus, see issue https://github.com/andstatus/andstatus/issues/538
if (empty($_REQUEST['client_name']) || empty($_REQUEST['redirect_uris'])) {
$postdata = Network::postdata();
if (!empty($postdata)) {
$_REQUEST = json_decode($postdata, true);
if (empty($_REQUEST)) {
DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Missing parameters'));
}
}
}
$name = $_REQUEST['client_name'] ?? ''; $name = $_REQUEST['client_name'] ?? '';
$redirect = $_REQUEST['redirect_uris'] ?? ''; $redirect = $_REQUEST['redirect_uris'] ?? '';
$scopes = $_REQUEST['scopes'] ?? ''; $scopes = $_REQUEST['scopes'] ?? 'read';
$website = $_REQUEST['website'] ?? ''; $website = $_REQUEST['website'] ?? '';
if (empty($name) || empty($redirect)) { if (empty($name) || empty($redirect)) {
@ -55,6 +67,10 @@ class Apps extends BaseApi
$fields['scopes'] = $scopes; $fields['scopes'] = $scopes;
} }
$fields['read'] = (stripos($scopes, 'read') !== false);
$fields['write'] = (stripos($scopes, 'write') !== false);
$fields['follow'] = (stripos($scopes, 'follow') !== false);
if (!empty($website)) { if (!empty($website)) {
$fields['website'] = $website; $fields['website'] = $website;
} }

View File

@ -21,6 +21,7 @@
namespace Friendica\Module; namespace Friendica\Module;
use Exception;
use Friendica\BaseModule; use Friendica\BaseModule;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\Core\System; use Friendica\Core\System;
@ -206,19 +207,13 @@ class BaseApi extends BaseModule
/** /**
* Get the application record via the proved request header fields * Get the application record via the proved request header fields
* *
* @param string $client_id
* @param string $client_secret
* @param string $redirect_uri
* @return array application record * @return array application record
*/ */
public static function getApplication() public static function getApplication(string $client_id, string $client_secret, string $redirect_uri)
{ {
$redirect_uri = $_REQUEST['redirect_uri'] ?? '';
$client_id = $_REQUEST['client_id'] ?? '';
$client_secret = $_REQUEST['client_secret'] ?? '';
if ((empty($redirect_uri) && empty($client_secret)) || empty($client_id)) {
Logger::warning('Incomplete request', ['request' => $_REQUEST]);
return [];
}
$condition = ['client_id' => $client_id]; $condition = ['client_id' => $client_id];
if (!empty($client_secret)) { if (!empty($client_secret)) {
$condition['client_secret'] = $client_secret; $condition['client_secret'] = $client_secret;
@ -264,14 +259,17 @@ class BaseApi extends BaseModule
* *
* @param array $application * @param array $application
* @param integer $uid * @param integer $uid
* @param string $scope
* @return array application record * @return array application record
*/ */
public static function createTokenForUser(array $application, int $uid) public static function createTokenForUser(array $application, int $uid, string $scope)
{ {
$code = bin2hex(random_bytes(32)); $code = bin2hex(random_bytes(32));
$access_token = bin2hex(random_bytes(32)); $access_token = bin2hex(random_bytes(32));
$fields = ['application-id' => $application['id'], 'uid' => $uid, 'code' => $code, 'access_token' => $access_token, 'created_at' => DateTimeFormat::utcNow(DateTimeFormat::MYSQL)]; $fields = ['application-id' => $application['id'], 'uid' => $uid, 'code' => $code, 'access_token' => $access_token, 'scopes' => $scope,
'read' => (stripos($scope, 'read') !== false), 'write' => (stripos($scope, 'write') !== false),
'follow' => (stripos($scope, 'follow') !== false), 'created_at' => DateTimeFormat::utcNow(DateTimeFormat::MYSQL)];
if (!DBA::insert('application-token', $fields, Database::INSERT_UPDATE)) { if (!DBA::insert('application-token', $fields, Database::INSERT_UPDATE)) {
return []; return [];
} }

View File

@ -27,6 +27,7 @@ use Friendica\Module\BaseApi;
/** /**
* @see https://docs.joinmastodon.org/spec/oauth/ * @see https://docs.joinmastodon.org/spec/oauth/
* @see https://aaronparecki.com/oauth-2-simplified/
*/ */
class Authorize extends BaseApi class Authorize extends BaseApi
{ {
@ -37,16 +38,29 @@ class Authorize extends BaseApi
public static function rawContent(array $parameters = []) public static function rawContent(array $parameters = [])
{ {
$response_type = $_REQUEST['response_type'] ?? ''; $response_type = $_REQUEST['response_type'] ?? '';
$client_id = $_REQUEST['client_id'] ?? '';
$client_secret = $_REQUEST['client_secret'] ?? ''; // Isn't normally provided. We will use it if present.
$redirect_uri = $_REQUEST['redirect_uri'] ?? '';
$scope = $_REQUEST['scope'] ?? 'read';
$state = $_REQUEST['state'] ?? '';
if ($response_type != 'code') { if ($response_type != 'code') {
Logger::warning('Wrong or missing response type', ['response_type' => $response_type]); Logger::warning('Unsupported or missing response type', ['request' => $_REQUEST]);
DI::mstdnError()->UnprocessableEntity(); DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Unsupported or missing response type'));
} }
$application = self::getApplication(); if (empty($client_id) || empty($redirect_uri)) {
Logger::warning('Incomplete request data', ['request' => $_REQUEST]);
DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Incomplete request data'));
}
$application = self::getApplication($client_id, $client_secret, $redirect_uri);
if (empty($application)) { if (empty($application)) {
DI::mstdnError()->UnprocessableEntity(); DI::mstdnError()->UnprocessableEntity();
} }
// @todo Compare the application scope and requested scope
$request = $_REQUEST; $request = $_REQUEST;
unset($request['pagename']); unset($request['pagename']);
$redirect = 'oauth/authorize?' . http_build_query($request); $redirect = 'oauth/authorize?' . http_build_query($request);
@ -66,11 +80,11 @@ class Authorize extends BaseApi
DI::session()->remove('oauth_acknowledge'); DI::session()->remove('oauth_acknowledge');
$token = self::createTokenForUser($application, $uid); $token = self::createTokenForUser($application, $uid, $scope);
if (!$token) { if (!$token) {
DI::mstdnError()->UnprocessableEntity(); DI::mstdnError()->UnprocessableEntity();
} }
DI::app()->redirect($application['redirect_uri'] . '?code=' . $token['code']); DI::app()->redirect($application['redirect_uri'] . '?' . http_build_query(['code' => $token['code'], 'state' => $state]));
} }
} }

View File

@ -29,39 +29,44 @@ use Friendica\Module\BaseApi;
/** /**
* @see https://docs.joinmastodon.org/spec/oauth/ * @see https://docs.joinmastodon.org/spec/oauth/
* @see https://aaronparecki.com/oauth-2-simplified/
*/ */
class Token extends BaseApi class Token extends BaseApi
{ {
public static function post(array $parameters = []) public static function post(array $parameters = [])
{ {
$client_secret = $_REQUEST['client_secret'] ?? '';
$code = $_REQUEST['code'] ?? '';
$grant_type = $_REQUEST['grant_type'] ?? ''; $grant_type = $_REQUEST['grant_type'] ?? '';
$code = $_REQUEST['code'] ?? '';
$redirect_uri = $_REQUEST['redirect_uri'] ?? '';
$client_id = $_REQUEST['client_id'] ?? '';
$client_secret = $_REQUEST['client_secret'] ?? '';
if ($grant_type != 'authorization_code') { if ($grant_type != 'authorization_code') {
Logger::warning('Unsupported or missing grant type', ['request' => $_REQUEST]); Logger::warning('Unsupported or missing grant type', ['request' => $_REQUEST]);
DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Unsupported or missing grant type')); DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Unsupported or missing grant type'));
} }
$application = self::getApplication(); if (empty($client_id) || empty($client_secret) || empty($redirect_uri)) {
Logger::warning('Incomplete request data', ['request' => $_REQUEST]);
DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Incomplete request data'));
}
$application = self::getApplication($client_id, $client_secret, $redirect_uri);
if (empty($application)) { if (empty($application)) {
DI::mstdnError()->UnprocessableEntity(); DI::mstdnError()->UnprocessableEntity();
} }
if ($application['client_secret'] != $client_secret) { // For security reasons only allow freshly created tokens
Logger::warning('Wrong client secret', $client_secret); $condition = ["`application-id` = ? AND `code` = ? AND `created_at` > UTC_TIMESTAMP() - INTERVAL ? MINUTE", $application['id'], $code, 5];
DI::mstdnError()->Unauthorized();
}
$condition = ['application-id' => $application['id'], 'code' => $code];
$token = DBA::selectFirst('application-token', ['access_token', 'created_at'], $condition); $token = DBA::selectFirst('application-token', ['access_token', 'created_at'], $condition);
if (!DBA::isResult($token)) { if (!DBA::isResult($token)) {
Logger::warning('Token not found', $condition); Logger::warning('Token not found or outdated', $condition);
DI::mstdnError()->Unauthorized(); DI::mstdnError()->Unauthorized();
} }
// @todo Use entity class $object = new \Friendica\Object\Api\Mastodon\Token($token['access_token'], 'Bearer', $application['scopes'], $token['created_at']);
System::jsonExit(['access_token' => $token['access_token'], 'token_type' => 'Bearer', 'scope' => $application['scopes'], 'created_at' => $token['created_at']]);
System::jsonExit($object->toArray());
} }
} }

View File

@ -0,0 +1,58 @@
<?php
/**
* @copyright Copyright (C) 2010-2021, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
namespace Friendica\Object\Api\Mastodon;
use Friendica\BaseDataTransferObject;
use Friendica\Util\DateTimeFormat;
/**
* Class Error
*
* @see https://docs.joinmastodon.org/entities/error
*/
class Token extends BaseDataTransferObject
{
/** @var string */
protected $access_token;
/** @var string */
protected $token_type;
/** @var string */
protected $scope;
/** @var string (Datetime) */
protected $created_at;
/**
* Creates a token record
*
* @param string $access_token
* @param string $token_type
* @param string $scope
* @param string $created_at
*/
public function __construct(string $access_token, string $token_type, string $scope, string $created_at)
{
$this->access_token = $access_token;
$this->token_type = $token_type;
$this->scope = $scope;
$this->created_at = DateTimeFormat::utc($created_at, DateTimeFormat::ATOM);
}
}

View File

@ -55,7 +55,7 @@
use Friendica\Database\DBA; use Friendica\Database\DBA;
if (!defined('DB_UPDATE_VERSION')) { if (!defined('DB_UPDATE_VERSION')) {
define('DB_UPDATE_VERSION', 1416); define('DB_UPDATE_VERSION', 1417);
} }
return [ return [
@ -436,6 +436,9 @@ return [
"redirect_uri" => ["type" => "varchar(255)", "not null" => "1", "comment" => ""], "redirect_uri" => ["type" => "varchar(255)", "not null" => "1", "comment" => ""],
"website" => ["type" => "varchar(255)", "comment" => ""], "website" => ["type" => "varchar(255)", "comment" => ""],
"scopes" => ["type" => "varchar(255)", "comment" => ""], "scopes" => ["type" => "varchar(255)", "comment" => ""],
"read" => ["type" => "boolean", "comment" => "Read scope"],
"write" => ["type" => "boolean", "comment" => "Write scope"],
"follow" => ["type" => "boolean", "comment" => "Follow scope"],
], ],
"indexes" => [ "indexes" => [
"PRIMARY" => ["id"], "PRIMARY" => ["id"],
@ -449,7 +452,11 @@ return [
"uid" => ["type" => "mediumint unsigned", "not null" => "1", "primary" => "1", "foreign" => ["user" => "uid"], "comment" => "Owner User id"], "uid" => ["type" => "mediumint unsigned", "not null" => "1", "primary" => "1", "foreign" => ["user" => "uid"], "comment" => "Owner User id"],
"code" => ["type" => "varchar(64)", "not null" => "1", "comment" => ""], "code" => ["type" => "varchar(64)", "not null" => "1", "comment" => ""],
"access_token" => ["type" => "varchar(64)", "not null" => "1", "comment" => ""], "access_token" => ["type" => "varchar(64)", "not null" => "1", "comment" => ""],
"created_at" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "creation time"], "created_at" => ["type" => "datetime", "not null" => "1", "comment" => "creation time"],
"scopes" => ["type" => "varchar(255)", "comment" => ""],
"read" => ["type" => "boolean", "comment" => "Read scope"],
"write" => ["type" => "boolean", "comment" => "Write scope"],
"follow" => ["type" => "boolean", "comment" => "Follow scope"],
], ],
"indexes" => [ "indexes" => [
"PRIMARY" => ["application-id", "uid"], "PRIMARY" => ["application-id", "uid"],

View File

@ -37,6 +37,26 @@
*/ */
return [ return [
"application-view" => [
"fields" => [
"id" => ["application", "id"],
"uid" => ["application-token", "uid"],
"name" => ["application", "name"],
"redirect_uri" => ["application", "redirect_uri"],
"website" => ["application", "website"],
"client_id" => ["application", "client_id"],
"client_secret" => ["application", "client_secret"],
"code" => ["application-token", "code"],
"access_token" => ["application-token", "access_token"],
"created_at" => ["application-token", "created_at"],
"scopes" => ["application-token", "scopes"],
"read" => ["application-token", "read"],
"write" => ["application-token", "write"],
"follow" => ["application-token", "follow"],
],
"query" => "FROM `application-token`
INNER JOIN `application` ON `application-token`.`application-id` = `application`.`id`"
],
"post-user-view" => [ "post-user-view" => [
"fields" => [ "fields" => [
"id" => ["post-user", "id"], "id" => ["post-user", "id"],

File diff suppressed because it is too large Load Diff

View File

@ -1,32 +1,25 @@
<div class="generic-page-wrapper">
<h1>{{$title}}</h1> <h1>{{$title}}</h1>
<form action="settings/oauth" method="post" autocomplete="off">
<input type='hidden' name='form_security_token' value='{{$form_security_token}}'>
<form action="settings/oauth" method="post" autocomplete="off"> <table id='application-block' class='table table-condensed table-striped'>
<input type='hidden' name='form_security_token' value='{{$form_security_token}}'> <thead>
<tr>
<div id="profile-edit-links"> <th>{{$name}}</th>
<ul> <th>{{$website}}</th>
<li> <th>{{$created_at}}</th>
<a id="profile-edit-view-link" href="{{$baseurl}}/settings/oauth/add">{{$add}}</a> </tr>
</li> </thead>
</ul> <tbody>
</div>
{{foreach $apps as $app}} {{foreach $apps as $app}}
<div class='oauthapp'> <tr>
<img src='{{$app.icon}}' class="{{if $app.icon}} {{else}}noicon{{/if}}"> <td>{{$app.name}}</td>
{{if $app.name}}<h4>{{$app.name}}</h4>{{else}}<h4>{{$noname}}</h4>{{/if}} <td>{{$app.website}}</td>
{{if $app.my}} <td>{{$app.created_at}}</td>
{{if $app.oauth_token}} <td><a href="{{$baseurl}}/settings/oauth/delete/{{$app.id}}?t={{$form_security_token}}" class="icon s22 delete" title="{{$delete}}">&nbsp;</a></td>
<div class="settings-submit-wrapper" ><button class="settings-submit" type="submit" name="remove" value="{{$app.oauth_token}}">{{$remove}}</button></div> </tr>
{{/if}}
{{/if}}
{{if $app.my}}
<a href="{{$baseurl}}/settings/oauth/edit/{{$app.client_id}}" class="icon s22 edit" title="{{$edit}}">&nbsp;</a>
<a href="{{$baseurl}}/settings/oauth/delete/{{$app.client_id}}?t={{$form_security_token}}" class="icon s22 delete" title="{{$delete}}">&nbsp;</a>
{{/if}}
</div>
{{/foreach}} {{/foreach}}
</tbody>
</form> </table>
</form>
</div>

View File

@ -1,44 +1,26 @@
<div class="generic-page-wrapper"> <div class="generic-page-wrapper">
{{* include the title template for the settings title *}} {{* include the title template for the settings title *}}
{{include file="section_title.tpl" title=$title }} {{include file="section_title.tpl" title=$title}}
<form action="settings/oauth" method="post" autocomplete="off"> <form action="settings/oauth" method="post" autocomplete="off">
<input type='hidden' name='form_security_token' value='{{$form_security_token}}'> <input type='hidden' name='form_security_token' value='{{$form_security_token}}'>
<table id='application-block' class='table table-condensed table-striped'>
<div id="profile-edit-links"> <thead>
<ul> <tr>
{{* <th>{{$name}}</th>
I commented this out. Initially I wanted to to load the oauth/add into a modal dialog but settings.php <th>{{$website}}</th>
does need $a->argv[2] === 'add' to work and argv[2] isn't available if you load a modal <th>{{$created_at}}</th>
I leave it at this place as reminder that we need an other solution in settings.php </tr>
</thead>
<li role="menuitem"> <tbody>
<a id="profile-edit-view-link" onclick="addToModal('{{$baseurl}}/settings/oauth/add')">{{$add}}</a>
</li>
*}}
<li role="menuitem">
<a id="profile-edit-view-link" href="{{$baseurl}}/settings/oauth/add">{{$add}}</a>
</li>
</ul>
</div>
{{foreach $apps as $app}} {{foreach $apps as $app}}
<div class='oauthapp'> <tr>
<img src='{{$app.icon}}' class="{{if $app.icon}} {{else}}noicon{{/if}}"> <td>{{$app.name}}</td>
{{if $app.name}}<h4>{{$app.name}}</h4>{{else}}<h4>{{$noname}}</h4>{{/if}} <td>{{$app.website}}</td>
{{if $app.my}} <td>{{$app.created_at}}</td>
{{if $app.oauth_token}} <td><a href="{{$baseurl}}/settings/oauth/delete/{{$app.id}}?t={{$form_security_token}}" class="btn" title="{{$delete}}"><i class="fa fa-trash" aria-hidden="true"></i></a></td>
<div class="settings-submit-wrapper" ><button class="settings-submit" type="submit" name="remove" value="{{$app.oauth_token}}">{{$remove}}</button></div> </tr>
{{/if}}
{{/if}}
{{if $app.my}}
<a href="{{$baseurl}}/settings/oauth/edit/{{$app.client_id}}" class="btn" title="{{$edit}}"><i class="fa fa-pencil-square-o" aria-hidden="true"></i>&nbsp;</a>
<a href="{{$baseurl}}/settings/oauth/delete/{{$app.client_id}}?t={{$form_security_token}}" class="btn" title="{{$delete}}"><i class="fa fa-trash" aria-hidden="true"></i></a>
{{/if}}
</div>
{{/foreach}} {{/foreach}}
</tbody>
</table>
</form> </form>
</div> </div>