mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-07 16:37:02 +03:00
O365 option to use Azure or Personal accounts #1645
This commit is contained in:
parent
3931c11255
commit
198cc852c3
2 changed files with 16 additions and 6 deletions
|
|
@ -1,11 +1,13 @@
|
||||||
(rl => {
|
(rl => {
|
||||||
const client_id = rl.pluginSettingsGet('login-o365', 'client_id'),
|
const client_id = rl.pluginSettingsGet('login-o365', 'client_id'),
|
||||||
|
// https://learn.microsoft.com/en-us/entra/identity-platform/reply-url#query-parameter-support-in-redirect-uris
|
||||||
|
query = rl.pluginSettingsGet('login-o365', 'personal') ? '' : '?',
|
||||||
tenant = rl.pluginSettingsGet('login-o365', 'tenant'),
|
tenant = rl.pluginSettingsGet('login-o365', 'tenant'),
|
||||||
login = () => {
|
login = () => {
|
||||||
document.location = 'https://login.microsoftonline.com/'+tenant+'/oauth2/v2.0/authorize?' + (new URLSearchParams({
|
document.location = 'https://login.microsoftonline.com/'+tenant+'/oauth2/v2.0/authorize?' + (new URLSearchParams({
|
||||||
response_type: 'code',
|
response_type: 'code',
|
||||||
client_id: client_id,
|
client_id: client_id,
|
||||||
redirect_uri: document.location.href.replace(/\/$/, '') + '/LoginO365',
|
redirect_uri: document.location.href.replace(/\/$/, '') + '/' + query + 'LoginO365',
|
||||||
scope: [
|
scope: [
|
||||||
// Associate personal info
|
// Associate personal info
|
||||||
'openid',
|
'openid',
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,9 @@
|
||||||
*
|
*
|
||||||
* https://portal.azure.com/#view/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/~/RegisteredApps
|
* https://portal.azure.com/#view/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/~/RegisteredApps
|
||||||
*
|
*
|
||||||
* redirect_uri=https://{DOMAIN}/?LoginO365
|
* https://learn.microsoft.com/en-us/entra/identity-platform/reply-url#query-parameter-support-in-redirect-uris
|
||||||
* redirect_uri=https://{DOMAIN}/LoginO365
|
* Azure: redirect_uri=https://{DOMAIN}/?LoginO365
|
||||||
|
* Personal: redirect_uri=https://{DOMAIN}/LoginO365
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use RainLoop\Model\MainAccount;
|
use RainLoop\Model\MainAccount;
|
||||||
|
|
@ -18,8 +19,8 @@ class LoginO365Plugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
{
|
{
|
||||||
const
|
const
|
||||||
NAME = 'Office365/Outlook OAuth2',
|
NAME = 'Office365/Outlook OAuth2',
|
||||||
VERSION = '0.2',
|
VERSION = '0.3',
|
||||||
RELEASE = '2024-08-13',
|
RELEASE = '2024-09-29',
|
||||||
REQUIRED = '2.36.1',
|
REQUIRED = '2.36.1',
|
||||||
CATEGORY = 'Login',
|
CATEGORY = 'Login',
|
||||||
DESCRIPTION = 'Office365/Outlook IMAP, Sieve & SMTP login using RFC 7628 OAuth2';
|
DESCRIPTION = 'Office365/Outlook IMAP, Sieve & SMTP login using RFC 7628 OAuth2';
|
||||||
|
|
@ -47,6 +48,7 @@ class LoginO365Plugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
|
|
||||||
public function httpPaths(array &$aPaths) : void
|
public function httpPaths(array &$aPaths) : void
|
||||||
{
|
{
|
||||||
|
// Personal accounts workaround
|
||||||
if (!empty($_SERVER['PATH_INFO']) && \str_ends_with($_SERVER['PATH_INFO'], 'LoginO365')) {
|
if (!empty($_SERVER['PATH_INFO']) && \str_ends_with($_SERVER['PATH_INFO'], 'LoginO365')) {
|
||||||
$aPaths = ['LoginO365'];
|
$aPaths = ['LoginO365'];
|
||||||
}
|
}
|
||||||
|
|
@ -113,7 +115,7 @@ class LoginO365Plugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
$iExpires += $aResponse['expires_in'];
|
$iExpires += $aResponse['expires_in'];
|
||||||
|
|
||||||
$oO365->setAccessToken($sAccessToken);
|
$oO365->setAccessToken($sAccessToken);
|
||||||
$aUserInfo = $oO365->fetch('https://graph.microsoft.com/oidc/userinfo"');
|
$aUserInfo = $oO365->fetch('https://graph.microsoft.com/oidc/userinfo');
|
||||||
if (200 != $aUserInfo['code']) {
|
if (200 != $aUserInfo['code']) {
|
||||||
throw new \RuntimeException("HTTP: {$aResponse['code']}");
|
throw new \RuntimeException("HTTP: {$aResponse['code']}");
|
||||||
}
|
}
|
||||||
|
|
@ -154,6 +156,12 @@ class LoginO365Plugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
public function configMapping() : array
|
public function configMapping() : array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
\RainLoop\Plugins\Property::NewInstance('personal')
|
||||||
|
->SetLabel('Use with personal accounts')
|
||||||
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
|
||||||
|
->SetDefaultValue(true)
|
||||||
|
->SetAllowedInJs()
|
||||||
|
->SetDescription('Sign in users with personal Microsoft accounts such as Outlook.com (Hotmail)'),
|
||||||
\RainLoop\Plugins\Property::NewInstance('client_id')
|
\RainLoop\Plugins\Property::NewInstance('client_id')
|
||||||
->SetLabel('Client ID')
|
->SetLabel('Client ID')
|
||||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING)
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue