I'm trying to send information to a Google Web Script (specifically, send a JSON object containing info to write to a Google Sheet) but I'm having trouble sending GET and POST requests to my Google Script.
I'm using Node.js and the "request" module to send the requests, but I don't receive what my doGet() and doPost() functions are supposed to return, instead I receive very long HTML files that are unrelated, some of which indicate a 404 error.
As an example:
Node.js
var request = require('request');
request("https://script.google.com/macros/s/my-web-script/exec", function (error, response, body) {
console.log(body);
});
Google Web Script:
function doGet(){
textOutput = ContentService.createTextOutput("Hello World! Welcome to the
web app.")
return textOutput
}
I published the web script and made it accessible to anyone. I'm not sure why this isn't working.
I think that both your scripts work fine. So can you confirm the situation of deployed Web Apps, again? When you modify your script, Web Apps has to be redeployed as a new version.
How to deploy Web Apps is as follows.
On the Script Editor
Publish
Deploy as Web App
Create new Project version
At Execute the app as, select "your account"
At Who has access to the app, select "Anyone, even anonymous"
Click "Deploy"
Copy "Current web app URL"
Click "OK"
The Current web app URL is https://script.google.com/macros/s/my-web-script/exec in your script.
The detail information is here.
If I misunderstand your question, I'm sorry.
Related
I'm building a desktop app using Electron and Vue as framework.
I also need to authenticate the user using Azure AD and I'm using msal-node.js as library to do that.
I'm able to authenticate with the server in azure and get the user info, but I cannot figure it out how to set the redirect URL.
First I have to say that the behaviour between dev and prod change drastically and I'm going to explain both scenarios and, in both of them I'm going to use history mode or not
DEV - using createWebHistory
Return Url in Azure and .env file: http://localhost:8080/
This is what I've got from the devTools during the normal navigation (no authenticated)
And this is what I've got after the authentication (the call to the API is successful):
Blank page in the app.
DEV - using createWebHashHistory
Return Url in Azure and .env file: http://localhost:8080/#/
After the authentication (failed):
Blank page in the app.
PROD
In prod I must use createWebHasHistory otherwise I've got blank page from the beginning.
The first problem I've got in production is the url itself.
When I create the window I call the following url:
await win.loadURL('app://./index.html')
In azure I cannot use the same url because it's not a valid url.
If I use just:
await win.loadURL('app://index.html')
I've got blank page
Any idea?
Thank you
The solution I've found it's pretty simple. Probably it's not the most "elegant", but it works, at least for prod. In dev I've still got the same weird problem described above.
Basically I'm starting a node server (localhost:3031 for example), within the app itself, then I'm catching the redirect url with it (localhost:3031/redirect) and serving the internal url from it:
expressApp.get('/redirect', async (req, res) => {
await win.loadURL('app://./index.html#about')
})
As I said, it works and I don't see any security issue with that, but, if you have any other idea or suggestion, please let me know.
Thank you
UPDATE
I've found the issue with Dev as well. In order to authenticate I'm using what Microsoft is suggesting in its documentation.
If you look at the file AuthProvider.js there is this portion of code, at the beginning:
const CUSTOM_FILE_PROTOCOL_NAME = process.env.REDIRECT_URI.split(':')[0];
Down below, in the method "getTokenIteractive" there is this other piece of code that applies the new protocol:
protocol.registerFileProtocol(CUSTOM_FILE_PROTOCOL_NAME, (req, callback) => {
const requestUrl = new URL(req.url)
callback(path.normalize(`${__dirname}/${requestUrl.path}`))
})
In Dev my REDIRECT_URI is "http://localhost:3031/redirect", but the app protocol must be "app" (or whatever you have chosen) in order to work with Vue. So, I've just wrapped this last method in a condition based on the environment and now everything works as expected everywhere.
I hope all this can be useful to someone.
I ran into a similar issue and your solution helped me out, thank you! Can I ask how you handled the logout redirect?
Also have you tried onBeforeRequest to handle the redirects, instead of a node server?
It was used as an example in an auth0 blog: https://auth0.com/blog/securing-electron-applications-with-openid-connect-and-oauth-2/
I have a service that shares html to multiple client web sites. I need to know The URL of where the request is coming from.
The client will add a custom script to their website and the script will load Firebase SDK and call one of my callable firebase functions.
exports.testFunction = functions.https.onCall(async (data, context) => {
//How do you access the requesting URL?
console.log(context.rawRequest.originalUrl) "/"
console.log(context.rawRequest.url) "/"
})
Thank you,
HTTP requests to callable functions don't really come "from" a URL. They come from anywhere on the internet. It could be a web site, Android or iOS app, or someone who simply knows the protocol to call the function.
If you're building a web app and you want to pass along the URL of the page making the request, you'll have to add that data into the object that the client passes to the function, which shows up in data.
I'm creating Cypress e2e tests, however our app is opened as a modal (iframe) on top of a parent page. As Cypress does not support iframes I decided to try and run app "standalone". However on start app is getting data from parent page via window.postMessage (info about flow and session). Is it possible to pass this data to app via Cypress?
I have tried to get data that we receive from backend via cy.request and it solves problem with session data, however I still can't figure out how to pass information about flow.
You can send a window.postMessage() in Cypress. Because Cypress runs in the browser next to your application, it has access to all web APIs.
In order to get a reference to the window object of your application, you can use cy.window()
Putting it all together, this is how you send a postMessage to your application under test:
cy.window() // get a reference to application's `window`
.then($window => {
const message = 'some data here'
$window.postMessage(message, '*')
})
Sending POST forms when visiting a page is indeed possible. As of Cypress 3.2.0, you can send POST requests using cy.visit.
You can check the cy.visit() docs for more details, but here is a quick code example of what you're trying to do:
cy.visit({
url: 'http://my-app.com/standalone-iframe-modal.html',
method: 'POST',
body: {
formKey: 'some-value',
anotherKey: 'some-other-value'
}
})
I'm currently testing a React front-end application with TestCafe. Current environment is:
React: 16.3.2
Node: 8.10.0
TestCafe: 0.23.0
MacOS Mojave 10.14.1
We've written about 65 tests which all run great. We've introduced a Single Sign On component into our application which has posed some automation challenges. Instead of trying to drive TestCafe against our app AND this particular SSO provider, we're using a fake API call instead.
Simplified order of operations for the app during normal usage is:
React app starts, detects no SSO credentials
Environmental service provides app with a proper SSO URL, react app redirects user to SSO login page using window.location
User logs in and SSO redirects back to our react app with a an additional URL query param & respective value.
React app proceeds forward in a 'logged in' state
Pretty basic stuff.
When the React app is being tested, we just provide different URLs which point to a local ExpressJS instance on localhost:3002. When the React app performs a window.location to the fake SSO API (http://localhost:3002/fakeOAuth) the ExpressJS instance simply performs a response.redirect(http://localhost:3000/?sso=fakeCode) and now we are back to our React app with the additional synthetic SSO data. This scheme works great when not being driven by TestCafe.
When we drive the React app via TestCafe, TestCafe hangs when returning back from the fake SSO call to the React app. After this hang, we have to forcefully kill TestCafe on the command line with a ctrl-c.
Using chrome debug tools and looking at the console output, there is a message:
Uncaught TypeError: __get$ is not a function
at hotCreateRequire (bundle.js:73)
at bundle.js:719
at bundle.js:722
and a screenshot can be found at the end of this post below.
The Test code:
import { Selector } from 'testcafe'
fixture 'Landing Page Body Tests'
.page 'localhost:3000'
test ('Displays correct main welcome title', async t => {
const landingPage = Selector('.card-title')
await t
.expect((landingPage).innerText).eql('Welcome, Fakeuser', 'Incorrect Username Found')
})
Screenshot of TestCafe failure
Does anyone have any ideas as to why TestCafe crashes? I have reworked the test a few times, researched and experimented with using TestCafe's Roles and ClientFunction classes but to no avail. Any input would be greatly appreciated.
It looks like a bug in TestCafe. The __get$function is an internal TestCafe function, and the __get$ is not a function error means that TestCafe wasn't able to process your page properly and install its internal functions in the global window object.
I suggest that you create a new bug report in the TestCafe repository, and provide a HAR report and an example that can be used to reproduce the problem.
I'm launching a Google Hangout from my webapp. I want to pass some data from my webapp to the Hangout window, and then back to my webapp. I am currently able to pass data back to my server with an AJAX post from the Hangout window, however, I then have to send this to the launching browser from my server.
Is there a direct line of communication from my launching app to the Google Hangouts app? I'm pretty new to webdev, so this might be an obvious question.
Well the thing you are trying to achieve here to get and post data from your hangout app and web application server, and you are already posting the data from hangout app to your webserver.You can write a route in your application the one running on your web server to return the data you are trying to fetch and again in your hangout app can make a ajax get action to get the required data in form of JSON or any required format, and grap the result in success callback of ajax.
example call:-
$.ajax({
type : "GET",
url:'/your_route_on_web_application/to_return_the_requested_data',
data : { any_data_you_want_to_pass: random_data},
dataType : 'json',
success : function(data) {
// do anything you want to with the received data
}
});