summaryrefslogtreecommitdiff
path: root/init.php
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2022-07-24 16:35:06 +0300
committerAndrew Dolgov <[email protected]>2022-07-24 16:35:06 +0300
commit77ef004d5ac39e6f2276deaee0b7298fef27819f (patch)
treee49fad8ffd77e04a94ba3d6caaf9a16c4f9d452f /init.php
parent2634afed889eea33eefd24629d21cadc09e80818 (diff)
add configuration variables
Diffstat (limited to 'init.php')
-rw-r--r--init.php55
1 files changed, 39 insertions, 16 deletions
diff --git a/init.php b/init.php
index 4ed6c78..4ac8004 100644
--- a/init.php
+++ b/init.php
@@ -9,6 +9,11 @@ class Auth_OIDC extends Auth_Base {
* TTRSS_AUTH_OIDC_POST_LOGOUT_URL=http://127.0.0.1/logout-redirect
*/
const AUTH_OIDC_POST_LOGOUT_URL = "AUTH_OIDC_POST_LOGOUT_URL";
+ const AUTH_OIDC_NAME = "AUTH_OIDC_NAME";
+ const AUTH_OIDC_URL = "AUTH_OIDC_URL";
+ const AUTH_OIDC_CLIENT_ID = "AUTH_OIDC_CLIENT_ID";
+ const AUTH_OIDC_CLIENT_SECRET = "AUTH_OIDC_CLIENT_SECRET";
+
/** @var PluginHost $host */
private $host;
@@ -21,35 +26,46 @@ class Auth_OIDC extends Auth_Base {
}
function init($host) {
- $host->add_hook($host::HOOK_AUTH_USER, $this);
-
Config::add(self::AUTH_OIDC_POST_LOGOUT_URL, "", Config::T_STRING);
+ Config::add(self::AUTH_OIDC_NAME, "", Config::T_STRING);
+ Config::add(self::AUTH_OIDC_URL, "", Config::T_STRING);
+ Config::add(self::AUTH_OIDC_CLIENT_ID, "", Config::T_STRING);
+ Config::add(self::AUTH_OIDC_CLIENT_SECRET, "", Config::T_STRING);
+
+ if (Config::get(self::AUTH_OIDC_URL)) {
+ $host->add_hook($host::HOOK_AUTH_USER, $this);
+ $host->add_hook($host::HOOK_LOGINFORM_ADDITIONAL_BUTTONS, $this);
- if (Config::get(self::AUTH_OIDC_POST_LOGOUT_URL) != "") {
- $host->add_hook($host::HOOK_POST_LOGOUT, $this);
+ if (Config::get(self::AUTH_OIDC_POST_LOGOUT_URL) != "")
+ $host->add_hook($host::HOOK_POST_LOGOUT, $this);
}
$this->host = $host;
}
function is_public_method($method) {
- return $method == "callback";
+ return $method == "oidc_login";
}
- function callback() {
- print "IN_CALLBACK";
- die;
+ public function oidc_login() : void {
+ $oidc = new OpenIDConnectClient(Config::get(self::AUTH_OIDC_URL),
+ Config::get(self::AUTH_OIDC_CLIENT_ID),
+ Config::get(self::AUTH_OIDC_CLIENT_SECRET));
+
+ $oidc->setRedirectURL(Config::get_self_url());
+ $oidc->addScope(['openid', 'profile', 'email']);
+ $oidc->authenticate();
}
function authenticate($login, $password, $service = '') {
- $oidc = new OpenIDConnectClient('https://auth.fakecake.org',
- 'dev-debian-ttrss',
- 'Bu3vuCi0wBeQteJ7di4H6SKgqvYnpSludEP68SHu9wLekxXl');
+ if (!($_SESSION['uid'] ?? false) && ($_REQUEST['code'] ?? false)) {
- if (!($_SESSION['uid'] ?? false)) {
- $oidc->setRedirectURL(Config::get_self_url());
+ $oidc = new OpenIDConnectClient(Config::get(self::AUTH_OIDC_URL),
+ Config::get(self::AUTH_OIDC_CLIENT_ID),
+ Config::get(self::AUTH_OIDC_CLIENT_SECRET));
try {
+ $oidc->setRedirectURL(Config::get_self_url());
$oidc->addScope(['openid', 'profile', 'email']);
$oidc->authenticate();
@@ -58,7 +74,6 @@ class Auth_OIDC extends Auth_Base {
$user_id = $this->auto_create_user($login, $password);
if ($user_id) {
-
$name = $oidc->requestUserInfo("name");
if ($name) {
@@ -77,14 +92,22 @@ class Auth_OIDC extends Auth_Base {
return $user_id;
} catch (Exception $e) {
- var_dump($e);
- die;
+ $_SESSION["login_error_msg"] = 'OIDC: ' . $e->getMessage();
}
}
return false;
}
+ function get_login_js() {
+ return file_get_contents(__DIR__ . "/init.js");
+ }
+
+ function hook_loginform_additional_buttons() {
+ print \Controls\button_tag(T_sprintf('Log in with %s', Config::get(self::AUTH_OIDC_NAME)), '',
+ ['class' => '', 'onclick' => 'Plugins.Auth_OIDC.login("'.htmlspecialchars($this->host->get_public_method_url($this, "oidc_login")).'")']);
+ }
+
function hook_post_logout($login, $user_id) {
return [
Config::get(self::AUTH_OIDC_POST_LOGOUT_URL)