diff --git a/configure.phtml b/configure.phtml
index 4396869..6f3eb8d 100644
--- a/configure.phtml
+++ b/configure.phtml
@@ -8,9 +8,27 @@
+
+
+
diff --git a/extension.php b/extension.php
index aff5bc4..e5a4119 100644
--- a/extension.php
+++ b/extension.php
@@ -22,9 +22,14 @@ class WallabagExtension extends Minz_Extension {
}
public function handleConfigureAction() {
+ $this->registerTranslates();
+
if (Minz_Request::isPost()) {
FreshRSS_Context::$user_conf->wallabag_endpoint = Minz_Request::param('wallabag_endpoint');
- FreshRSS_Context::$user_conf->wallabag_token = Minz_Request::param('wallabag_token');
+ FreshRSS_Context::$user_conf->wallabag_client_id = Minz_Request::param('wallabag_client_id');
+ FreshRSS_Context::$user_conf->wallabag_client_secret = Minz_Request::param('wallabag_client_secret');
+ FreshRSS_Context::$user_conf->wallabag_username = Minz_Request::param('wallabag_username');
+ FreshRSS_Context::$user_conf->wallabag_password = Minz_Request::param('wallabag_password');
FreshRSS_Context::$user_conf->wallabag_feeds = Minz_Request::param('wallabag_feeds', '');
FreshRSS_Context::$user_conf->wallabag_use_tags = Minz_Request::param('wallabag_use_tags', '');
FreshRSS_Context::$user_conf->wallabag_add_tags = Minz_Request::param('wallabag_add_tags', '');
@@ -32,17 +37,46 @@ class WallabagExtension extends Minz_Extension {
}
}
+ public function oauth($refresh_token = null) {
+ $endpoint = FreshRSS_Context::$user_conf->wallabag_endpoint;
+ $client_id = FreshRSS_Context::$user_conf->wallabag_client_id;
+ $client_secret = FreshRSS_Context::$user_conf->wallabag_client_secret;
+ $username = FreshRSS_Context::$user_conf->wallabag_username;
+ $password = FreshRSS_Context::$user_conf->wallabag_password;
+ if (is_null($endpoint) || is_null($client_id) || is_null($client_secret) || is_null($password) || is_null($username)) {
+ return null;
+ }
+
+ if (is_null($refresh_token)) {
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL, join_path($endpoint, 'oauth/v2/token'));
+ curl_setopt($ch, CURLOPT_POST, true);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
+ 'grant_type' => 'password',
+ 'client_id' => $client_id,
+ 'client_secret' => $client_secret,
+ 'username' => $username,
+ 'password' => $password,
+ ]));
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ $result = curl_exec($ch);
+ curl_close($ch);
+ return(json_decode($result, true));
+ }
+ }
+
public function wallabag(FreshRSS_Entry $entry): FreshRSS_Entry {
$endpoint = FreshRSS_Context::$user_conf->wallabag_endpoint;
- $token = FreshRSS_Context::$user_conf->wallabag_token;
+ if (is_null($endpoint)) {
+ return $entry;
+ }
$feeds = explode(',', FreshRSS_Context::$user_conf->wallabag_feeds);
$use_tags = FreshRSS_Context::$user_conf->wallabag_use_tags;
$add_tags = explode(',', FreshRSS_Context::$user_conf->wallabag_add_tags);
- if (is_null($endpoint) || is_null($token)) {
- return $entry;
- }
if (in_array($entry->feedId(), $feeds)) {
+ $token = $this->oauth()['access_token'];
+
$tags = $add_tags;
if ($use_tags) {
$tags = array_merge($tags, $entry->tags());
@@ -53,11 +87,11 @@ class WallabagExtension extends Minz_Extension {
curl_setopt($ch, CURLOPT_URL, join_path($endpoint, 'api/entries'));
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
- "Authorization:Bearer $token",
+ "Authorization:Bearer $token",
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
- 'url' => $link,
- 'tags' => join(',', $tags),
+ 'url' => $link,
+ 'tags' => join(',', $tags),
]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
diff --git a/i18n/en/ext.php b/i18n/en/ext.php
index ade1a7d..3b0348f 100644
--- a/i18n/en/ext.php
+++ b/i18n/en/ext.php
@@ -3,7 +3,10 @@
return array(
'wallabag' => array(
'endpoint' => 'Wallabag Endpoint',
- 'token' => 'Wallabag API Token',
+ 'client_id' => 'Wallabag Client ID',
+ 'client_secret' => 'Wallabag Client Secret',
+ 'username' => 'Wallabag Username',
+ 'password' => 'Wallabag Password',
'feeds' => 'Feed IDs (comma seperated)',
'use_tags' => 'Use tags?',
'add_tags' => 'Additional tags (comma seperated)',