0
votes

I have created a project in express

const express = require('express');
const app = express();

const PORT = 5555;


app.listen(PORT, () => {
    console.log(`Server running on port ${PORT}`);
});

app.get('/tr', (req, res, next) => {
    res.json({ status: 200, data: 'tr' })
});

app.get('/po', (req, res, next) => {
    res.json({ status: 200, data: 'po' })
});

module.exports = {
    app
};

deployed on cloud function with name my-transaction

and i am scheduling with google clound giving the url like

http://url/my-transaction/po

When I deployed without authentiation scheduler runs job success, but when I do with authentication it fails.

similary if i create a sample project like below

exports.helloHttp = (req, res) => {
    res.json({ status: 200, data: 'test hello' })
  };

and deploy similary configuring same as above with authentication it works.

only differce is in last function name is similar to entry point means while above entry point is app with different end points.

any help, appreciated Thanks

1

1 Answers

0
votes

This is because you need to add auth information to your http requests on cloud Scheduler

First you need to create a service account with the role Cloud Functions Invoker

when you have created the service account, you can see that has a email associated fro example:

[email protected]

After that you can create a new scheduler job with auth information by following these steps:

  1. Select target http
  2. Write the url (cloud function url)
  3. Click on "show more"
  4. Select Auth header > Add OIDC token
  5. Write the full email address of the service account

This new job scheduler will be send the http request with the auth infromation to execute successfully your cloud function.