Skip to content

Instantly share code, notes, and snippets.

@babelouest
Last active June 5, 2022 21:41
Show Gist options
  • Save babelouest/9c0ca17224ade7c4e763b3c1c37d21ae to your computer and use it in GitHub Desktop.
Save babelouest/9c0ca17224ade7c4e763b3c1c37d21ae to your computer and use it in GitHub Desktop.
Simple rainloop plugin to login to the webmail using oidc server, dovecot master password and apache module auth_openidc - Download those files in a directory named oidc-master-password-login/
<?php
// Copyright 2020 Nicolas Mora <[email protected]>
// License MIT
// There's room for improvement
class ExternalHeaderLoginPlugin extends \RainLoop\Plugins\AbstractPlugin
{
public function Init()
{
$this->addHook('filter.login-credentials', 'OverrideLoginСredentials');
$this->addHook('filter.app-data', 'FilterAppData');
}
public function configMapping()
{
return array(
\RainLoop\Plugins\Property::NewInstance('header_username')->SetLabel('Header Username')
->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT)
->SetDescription('Header key containing the username')
->SetDefaultValue("OIDC_CLAIM_userid"),
\RainLoop\Plugins\Property::NewInstance('master_username')->SetLabel('Master Username and separator')
->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT)
->SetDescription('IMAP Master username and separator')
->SetDefaultValue("*masteruser"),
\RainLoop\Plugins\Property::NewInstance('master_password')->SetLabel('Master Password')
->SetType(\RainLoop\Enumerations\PluginPropertyType::PASSWORD)
->SetDescription('IMAP Master password')
->SetDefaultValue("password"),
);
}
public function FilterAppData($bAdmin, &$aResult)
{
if (!$bAdmin && \is_array($aResult) && isset($aResult['Auth']) && !$aResult['Auth'])
{
$aResult['DevEmail'] = $_SERVER[$this->Config()->Get('plugin', 'header_username', '')];
$aResult['DevPassword'] = APP_DUMMY;
}
}
public function OverrideLoginСredentials(&$sEmail, &$sLogin, &$sPassword)
{
$sLogin = $_SERVER[$this->Config()->Get('plugin', 'header_username', '')].$this->Config()->Get('plugin', 'master_username', '');
$sPassword = $this->Config()->Get('plugin', 'master_password', '');
}
}
@babelouest
Copy link
Author

Due to rainloop lack of activity, I don't recommend to use this plugin anymore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment