Search Support

Avoid support scams. We will never ask you to call or text a phone number or share personal information. Please report suspicious activity using the “Report Abuse” option.

Learn More

I'm using Google Apps Script1 to login to a website, except the intended page doesn't appear.

  • 2 replies
  • 1 has this problem
  • 2 views
  • Last reply by cor-el

more options

I'm not certain if this is the appropriate forum. However, maybe someone understands header options and cookies.

If I execute the following google apps script I receive a blank dialog with a title of "demo", and a response code of 302. This dialog is attached.

If I next click on the "follow redirects" message I receive a error dialog, and this is also attached.

I'm kind of in the dark regarding authentication. Does someone know if there is a problem with the options, or if it's something else?

Thanks,


function logon0() {

 //
 // Logon to dashboard
 //
 var url = "https://www.######.com/login";
 var user = "######";
 var password = "######"; 
 var options = {muteHttpExceptions: true,
                followRedirects: false};
 options.headers = {"Authorization": "Basic " + Utilities.base64Encode(user + ":" + password) };
 var response = UrlFetchApp.fetch(url, options);
 var cookie = response.getAllHeaders()['Set-Cookie']; 
 var opt2 = {muteHttpExceptions: true,
             "headers":
                 {Cookie: cookie},
             followRedirects: false
            };
 var response2 = UrlFetchApp.fetch("https://www.######.com/app/v4/dashboard",opt2);
 var ui = HtmlService.createHtmlOutput(response2.getContentText());
 SpreadsheetApp.getUi().showModelessDialog(ui,"demo");
 Logger.log(response2.getContentText());

}


I'm not certain if this is the appropriate forum. However, maybe someone understands header options and cookies. If I execute the following google apps script I receive a blank dialog with a title of "demo", and a response code of 302. This dialog is attached. If I next click on the "follow redirects" message I receive a error dialog, and this is also attached. I'm kind of in the dark regarding authentication. Does someone know if there is a problem with the options, or if it's something else? Thanks, -------------------------------------------------------------------------------------------------- function logon0() { // // Logon to dashboard // var url = "https://www.######.com/login"; var user = "######"; var password = "######"; var options = {muteHttpExceptions: true, followRedirects: false}; options.headers = {"Authorization": "Basic " + Utilities.base64Encode(user + ":" + password) }; var response = UrlFetchApp.fetch(url, options); var cookie = response.getAllHeaders()['Set-Cookie']; var opt2 = {muteHttpExceptions: true, "headers": {Cookie: cookie}, followRedirects: false }; var response2 = UrlFetchApp.fetch("https://www.######.com/app/v4/dashboard",opt2); var ui = HtmlService.createHtmlOutput(response2.getContentText()); SpreadsheetApp.getUi().showModelessDialog(ui,"demo"); Logger.log(response2.getContentText()); } -------------------------------------------------------------------------------------------------------
Attached screenshots

All Replies (2)

more options

Do you have some reason to suspect that Lumosity supports basic access authentication? If it did, you wouldn't need any cookies. It looks like cookies are obtained via POST request to "www.lumosity.com/authentication" rather than requesting "www.lumosity.com/login"

Do you particularly want to do this with Lumosity, or is it just an example. It would be easier to start with a few that have a documented login process for learning purposes.

more options

This can happen if you open a website in a (i)frame and the website prohibits this via CSP.