My organisation is using Vouch Proxy to protect a subdomain. I'd like to be able use something like an oauth token to login, similar to the below.
I'm hoping that someone can use the link above to point me in the right direction.
Is there a way to create and retain a cookie in order to make UrlFetchApp requests?
GAS:
var token = ScriptApp.getOAuthToken();
var header = {"Authorization":"Bearer " + token};
var options = {
"method":"GET",
"headers": header,
"muteHttpExceptions": true
};
var url = 'url'
var response =UrlFetchApp.fetch(url, options);
Logger.log(response.getResponseCode()); //returns 200
Logger.log(response.getContentText()); // returns 'sign in with Google' HTML
EDIT
The following also returns the 'sign in with Google' HTML.
function fetchUrlWithCookie() {
var url = 'https://vouch.oursites.com/login?url=https://private.oursites.com';
var response = UrlFetchApp.fetch(url, {
muteHttpExceptions: true,
followRedirects: false,
headers: {"Authorization":"Bearer " + ScriptApp.getOAuthToken()}
});
var cookie = response.getAllHeaders()['Set-Cookie']; //Get cookie from header
response = UrlFetchApp.fetch(url, {
muteHttpExceptions: true,
followRedirects: true,
headers: {
Cookie: cookie, //send the cookie we got as header
},
});
Logger.log(response.getContentText());
}
I have also tried using basic auth with a less secure app password, with the same result.