# How do i secure a webtask

**URL:** <https://community.auth0.com/t/how-do-i-secure-a-webtask/6203>\
**Category:** Get Help\
**Tags:** webhooks, webtask, auth0\
**Created:** [April 13, 2017, 3:49am UTC](https://community.auth0.com/t/how-do-i-secure-a-webtask/6203 "2017-04-13T03:49:35Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![nikhil.kartha](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@nikhil.kartha](https://community.auth0.com/u/nikhil.kartha)\
**Post date:** [April 13, 2017, 3:49am UTC](https://community.auth0.com/t/how-do-i-secure-a-webtask/6203/1 "2017-04-13T03:49:35Z")

</div>

How do i secure a webtask, to only allow processing events coming in from a specific auth0/webhook

#### From the Webtask

Doing this

```
wt create refresh-token.js -s AUTH0_CLIENT_ID=XXXXX -s AUTH0_CLIENT_SECRET=XXXXX -s AUTH0_DOMAIN=XXXXX
```

Makes the command line variables available as context.secrets.AUTH0\_CLIENT\_ID and context.secrets.AUTH0\_SECRET (also shows up under “webtask editor/secrets” tab)

Is this supposed to secure the webtask, i can still acess the url (froma browser), and see the output from the callback.

#### From the Webhook auth0 extension

The ‘Scheduled jobs/Secrets’ tab shows entries for AUTH0\_\* keys which i didnt explicitly set, what do they defaul to.

---

<div class="post-metadata">

**Author:** ![prashantT](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/prashantt/32/6002_2.png) [@prashantT](https://community.auth0.com/u/prashantT)\
**Post date:** [April 13, 2017, 11:12am UTC](https://community.auth0.com/t/how-do-i-secure-a-webtask/6203/2 "2017-04-13T11:12:24Z")

</div>

There are several methods to protect access to webtasks, depending on the use case. To restrict calls made from a Hook, you can think of it as a machine-to-machine flow, and use the [Client Credentials Grant](https://auth0.com/docs/api-auth/grant/client-credentials). In essence, your webtask will be the ‘API’, with the Hook being the client. Take a look at the following documentation that may be of help:

- [https://auth0.com/docs/api-auth/grant/client-credentials](https://auth0.com/docs/api-auth/grant/client-credentials)
- [https://webtask.io/docs/auth](https://webtask.io/docs/auth)

---

<div class="post-metadata">

**Author:** ![nikhil.kartha](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@nikhil.kartha](https://community.auth0.com/u/nikhil.kartha)\
**Post date:** [April 21, 2017, 2:59am UTC](https://community.auth0.com/t/how-do-i-secure-a-webtask/6203/3 "2017-04-21T02:59:29Z")

</div>

I was having trouble (submit button wouldnt respond)) copying a longish comment in markdown, hence replied to the email notification. Tried the inline editor, and splitting into multiple comments too.

---

<div class="post-metadata">

**Author:** ![nikhil.kartha](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@nikhil.kartha](https://community.auth0.com/u/nikhil.kartha)\
**Post date:** [April 21, 2017, 3:01am UTC](https://community.auth0.com/t/how-do-i-secure-a-webtask/6203/4 "2017-04-21T03:01:00Z")

</div>

### I have this webtask

```javascript
//hello.js

var wt = require('webtask-tools');

function webtask(context, req, res) { 
    console.log("from hello");
    console.log("EVENT TYPE:" + context.data.type);

    res.writeHead(200, { 'Content-Type': 'text/html '});
    res.end('<h1>FROM HELLO</h1>');
}

module.exports = wt.auth0(webtask);

```

### I Run it like this:

```bash
wt create hello.js -s AUTH0_CLIENT_ID=XXXXX -s AUTH0_CLIENT_SECRET=XXXXX -s AUTH0_DOMAIN=XXXXX

```

---

<div class="post-metadata">

**Author:** ![nikhil.kartha](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@nikhil.kartha](https://community.auth0.com/u/nikhil.kartha)\
**Post date:** [April 21, 2017, 3:02am UTC](https://community.auth0.com/t/how-do-i-secure-a-webtask/6203/5 "2017-04-21T03:02:27Z")

</div>

## Configured auth0 webhook extension

Configured the autho API hook plugin with the AUTH0 ID, SECRET and DOMAIN, used in the ‘wt create’ call above.

### LOGS (webhook and webtask)

I see this in the auth0 webhook extension logs:

```bash
12:13:07 PM: Unexpected response while sending request: {“code”:401,“message”:“Unauthorized.“,”error”:“Missing access token.“,”redirect”:“https://XXXXX-0.run.webtask.io/hello/login“}

```

And this in the webtask (wt logs):

```bash
[19:13:07.395Z] INFO wt: finished webtask request 1492715587282.271021 with HTTP 401 in 89ms

```

---

<div class="post-metadata">

**Author:** ![nikhil.kartha](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@nikhil.kartha](https://community.auth0.com/u/nikhil.kartha)\
**Post date:** [April 21, 2017, 3:03am UTC](https://community.auth0.com/t/how-do-i-secure-a-webtask/6203/6 "2017-04-21T03:03:57Z")

</div>

Why isnt the webhook sending an access token in its request.

---

<div class="post-metadata">

**Author:** ![nikhil.kartha](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@nikhil.kartha](https://community.auth0.com/u/nikhil.kartha)\
**Post date:** [April 21, 2017, 7:01am UTC](https://community.auth0.com/t/how-do-i-secure-a-webtask/6203/7 "2017-04-21T07:01:09Z")

</div>

The current auth0/webhook extension does a plain POST to the webtask(webhook\_url), the auth0 creds are only used to get the logs from auth0.

We could probably move the webtask(which deletes refresh tokens) to the point where a POST is done in the webhook, or we could modify the POST to do oauth. But we dont want to maintain our own version of the extension.

I guess what we want is a version of the webhook extension, that speaks oauth with the WEBHOOK\_URL.

---

<div class="post-metadata">

**Author:** ![Glenn\_Block](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/glenn_block/32/4451_2.png) [@Glenn\_Block](https://community.auth0.com/u/Glenn_Block)\
**Post date:** [March 8, 2018, 12:40am UTC](https://community.auth0.com/t/how-do-i-secure-a-webtask/6203/9 "2018-03-08T00:40:29Z")

</div>

This blog post may be useful: [https://auth0.com/blog/securing-webtasks-part-2-using-middleware/](https://auth0.com/blog/securing-webtasks-part-2-using-middleware/)

---

<div class="post-metadata">

**Author:** ![jerdog](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jerdog/32/11231_2.png) [@jerdog](https://community.auth0.com/u/jerdog)\
**Post date:** [March 8, 2018, 1:11am UTC](https://community.auth0.com/t/how-do-i-secure-a-webtask/6203/10 "2018-03-08T01:11:54Z")

</div>



---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [July 25, 2019, 11:04am UTC](https://community.auth0.com/t/how-do-i-secure-a-webtask/6203/11 "2019-07-25T11:04:55Z")

</div>


