Use SNAPPYMAIL_INCLUDE_AS_API and added SSO test

This commit is contained in:
the-djmaze 2022-01-10 16:10:56 +01:00
parent dd6779b1a8
commit 7f084dda53
4 changed files with 29 additions and 8 deletions

View file

@ -65,12 +65,12 @@ class SnappyMailHelper {
{
self::regSnappyMailDataFunction();
$_ENV['RAINLOOP_INCLUDE_AS_API'] = true;
$_ENV['SNAPPYMAIL_INCLUDE_AS_API'] = true;
include $sPath;
if (class_exists('\\SnappyMail\\Api'))
if (class_exists('\\RainLoop\\Api'))
{
$SsoHash = \SnappyMail\Api::GetUserSsoHash($sEmail, $sPassword);
$SsoHash = \RainLoop\Api::GetUserSsoHash($sEmail, $sPassword);
}
}
@ -238,10 +238,10 @@ class SnappyMailHelper {
self::regSnappyMailDataFunction();
$_ENV['RAINLOOP_INCLUDE_AS_API'] = true;
$_ENV['SNAPPYMAIL_INCLUDE_AS_API'] = true;
include $sApiPath;
\SnappyMail\Api::LogoutCurrentLogginedUser();
\RainLoop\Api::LogoutCurrentLogginedUser();
return true;
}

View file

@ -661,8 +661,8 @@ class ServiceActions
$sEmail = \trim($aData['Email']);
$sPassword = $aData['Password'];
$aAdditionalOptions = isset($aData['AdditionalOptions']) && \is_array($aData['AdditionalOptions']) &&
\count($aData['AdditionalOptions']) ? $aData['AdditionalOptions'] : null;
$aAdditionalOptions = (isset($aData['AdditionalOptions']) && \is_array($aData['AdditionalOptions']))
? $aData['AdditionalOptions'] : [];
try
{

View file

@ -158,7 +158,7 @@ if (!defined('RAINLOOP_APP_LIBRARIES_PATH')) {
if (class_exists('RainLoop\\Api')) {
RainLoop\Api::Handle();
// NextCloud/OwnCloud?
if (empty($_ENV['RAINLOOP_INCLUDE_AS_API'])) {
if (empty($_ENV['SNAPPYMAIL_INCLUDE_AS_API'])) {
RainLoop\Service::Handle();
exit(0);
}

21
test/sso.php Normal file
View file

@ -0,0 +1,21 @@
<?php
// Enable SnappyMail Api and include index file
$_ENV['SNAPPYMAIL_INCLUDE_AS_API'] = true;
require '../index.php';
/**
* Get SSO hash
*/
$aAdditionalOptions = array(
// One of /snappymail/v/0.0.0/app/localization/*
// 'Language' = 'en-US'
);
$bUseTimeout = true; // 10 seconds
$ssoHash = \RainLoop\Api::CreateUserSsoHash($sEmail, $sPassword, $aAdditionalOptions, $bUseTimeout);
// redirect to webmail sso url
\header('Location: https://yourdomain.com/snappymail/?sso&hash='.$ssoHash);
// Destroy the SSO hash
//\RainLoop\Api::ClearUserSsoHash($ssoHash);