Created
June 1, 2018 17:26
-
-
Save julestruong/dce3f4160d88efa1ed773af0daf031bc to your computer and use it in GitHub Desktop.
Groupama Authent bug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function validateCredentials(request: any) { | |
const logClient = console; | |
// Always Trace the Lambda event and context | |
logClient.log(`request : [${JSON.stringify(request)}]`); | |
const body = (request.body && JSON.parse(request.body)) || undefined; | |
// Check that the received body contains the required informations | |
// For security reasons do not return a menaingfull message to the caller | |
// The problem is explained in the logs | |
if (!body) { | |
logClient.log("Please provide a valid body for this request."); | |
return new api.ApiResponse( | |
"Please provide a valid body for this request", | |
{ "Content-Type": "text/plain" }, | |
500 | |
); | |
} | |
if (!body.email) { | |
logClient.log( | |
"Please provide a valid body for this request. email is missing" | |
); | |
return new api.ApiResponse( | |
"Please provide a valid body for this request", | |
{ "Content-Type": "text/plain" }, | |
500 | |
); | |
} | |
if (!body.password) { | |
logClient.log( | |
"Please provide a valid body for this request. email is missing" | |
); | |
return new api.ApiResponse( | |
"Please provide a valid body for this request.", | |
{ "Content-Type": "text/plain" }, | |
500 | |
); | |
} | |
if (!process.env["EWS_URL"]) { | |
logClient.log("Please provide a valid value for prameter EWS_URL"); | |
return new api.ApiResponse( | |
"Module not configured properly. EWS_URL is not defined", | |
{ "Content-Type": "text/plain" }, | |
500 | |
); | |
} | |
if (!process.env["EXCHANGE_VERSION"]) { | |
logClient.log("Please provide a valid value for prameter EXCHANGE_VERSION"); | |
return new api.ApiResponse( | |
"Module not configured properly. EXCHANGE_VERSION is not defined", | |
{ "Content-Type": "text/plain" }, | |
500 | |
); | |
} | |
const email = body.email; | |
const password = body.password; | |
// Set the default value | |
var exchangeVersion: ExchangeVersion = ExchangeVersion.Exchange2010_SP2; | |
// use value from the environment | |
// note that string | undefined (from env[]) is defeated with +"" | |
if (process.env["EXCHANGE_VERSION"] !== undefined) | |
exchangeVersion = +(process.env["EXCHANGE_VERSION"] + ""); | |
const exch = new ExchangeService(exchangeVersion); | |
const exchangeUri = process.env["EWS_URL"] + ""; // 'https://webmail.groupama-immobilier.fr/ews/Exchange.asmx'; | |
exch.Url = new Uri(exchangeUri); | |
// Credentials are mandatory | |
exch.Credentials = new WebCredentials(email, password); | |
// This is specific to Groupama Immobilier where EWS is sitting behind an ISA Server. | |
ConfigurationApi.ConfigureXHR(new cookieAuthXhrApi(email, password)); | |
var succeeded = false; | |
try { | |
// This very simple operation will perform a roundtrip to the server, validating the credentials. | |
const inbox: Folder = await Folder.Bind(exch, WellKnownFolderName.Inbox); | |
succeeded = true; | |
} catch (e) { | |
// Don't care about the error | |
logClient.log("error", e); | |
} | |
return { data: { result: succeeded } }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment