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

[WIP] new Keycloak Login Provider Plugin via OIDC #822

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"colinodell/json5": "^2.3",
"doctrine/annotations": "^1.14.3",
"guzzlehttp/guzzle": "^7.7",
"jumbojett/openid-connect-php": "^0.9.10",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it ok to require the OIDC Libary via composer? The Simplesaml Class from other Plugins is not required.

Copy link
Owner

Choose a reason for hiding this comment

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

I would rather not put it there. I try to only keep the dependencies in the main composer.json that will be part of the main distribution via ZIP file, without any plugins. So I don't want to put extra weight in there for this, the SAML or Redis parts. On the servers with those plugins, I do take some extra steps therefore, by manually installing yiisoft/yii2-redis predis/predis simplesamlphp/simplesamlphp after updating the dependencies.

"paragonie/sodium_compat": "^1.20",
"phpoffice/phpspreadsheet": "^1.28",
"s1syphos/php-simple-captcha": "^2.3",
Expand Down
221 changes: 220 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions plugins/keycloak_oidc_login/Module.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

namespace app\plugins\keycloak_oidc_login;

use app\components\LoginProviderInterface;
use app\plugins\ModuleBase;

class Module extends ModuleBase
{
public const LOGIN_KEY = 'keycloak_oidc';
public const AUTH_KEY_USERS = 'keycloak_oidc';

private static ?LoginProviderInterface $loginProvider = null;

public static function getDedicatedLoginProvider(): ?LoginProviderInterface
{
if (self::$loginProvider === null) {
self::$loginProvider = new OidcLogin(
'https://keycloak.domain.com',
'antragsgruen.domain.com',
'supderdupersecret'
Comment on lines +21 to +23
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would love to set these credentials in the config.json - in the Admin panels would be ok too but if this would ever be the only way to log in (is this even possible right now?) then it would difficult to change these values if ever needed.

Copy link
Owner

Choose a reason for hiding this comment

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

Yea, I don't have a really good way of storing plugin-specific credentials. For the discourse-plugin (✝) I put the configuration in a separate file next to the config.json : https://github.com/CatoTH/antragsgruen/blob/main/plugins/discourse/Module.php#L31

Using the admin panel would work too, using something like https://github.com/CatoTH/antragsgruen/blob/main/plugins/member_petitions/Module.php#L65 , but might be an overkill there

);
}
return self::$loginProvider;
}

public static function getManagerUrlRoutes(string $domainPlain): array
{
return [
$domainPlain . '/keycloak-oidc' => '/keycloak_oidc_login/login/login',
];
}

public static function getAllUrlRoutes(array $urls, string $dom, string $dommotion, string $dommotionOld, string $domamend, string $domamendOld): array
{
return array_merge(
[
$dom . 'keycloak-oidc' => '/keycloak_oidc_login/login/login',
],
parent::getAllUrlRoutes($urls, $dom, $dommotion, $dommotionOld, $domamend, $domamendOld)
);
}
}
Loading