X
Tap here to go to the mobile version of the site.

Support Forum

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

Posted

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
Quote

Additional System Details

Installed Plug-ins

  • Shockwave Flash 32.0 r0

Application

  • User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:72.0) Gecko/20100101 Firefox/72.0

More Information

Matthew Thomas
  • Top 25 Contributor
13 solutions 90 answers

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.

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.
Was this helpful to you?
Quote
cor-el
  • Top 10 Contributor
  • Moderator
17862 solutions 161638 answers

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

This can happen if you open a website in a (i)frame and the website prohibits this via CSP.
Was this helpful to you?
Quote
Ask a question

You must log in to your account to reply to posts. Please start a new question, if you do not have an account yet.