# Create an access\_token in a cron job

**URL:** <https://community.auth0.com/t/create-an-access-token-in-a-cron-job/72871>\
**Category:** Get Help\
**Tags:** client\_credentials\
**Created:** [November 10, 2021, 2:37am UTC](https://community.auth0.com/t/create-an-access-token-in-a-cron-job/72871 "2021-11-10T02:37:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![katlim-br](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/katlim-br/32/32876_2.png) [@katlim-br](https://community.auth0.com/u/katlim-br)\
**Post date:** [November 10, 2021, 2:37am UTC](https://community.auth0.com/t/create-an-access-token-in-a-cron-job/72871/1 "2021-11-10T02:37:49Z")

</div>

Hello  
I still haven’t fully implemented Auth0 but I’m starting to do so, and this issue seems to be a blocker for me.

So we will use Auth0 with organizations, and for our web application it should work ok.

However, we will have many cron jobs running on behalf of this orgs, and we wanted to uniformize the access to our business logic that is contained in an API. Yet if we want to create a client\_credentials token, then according to your documentation, it would not be possible.

So the question is, how can we handle that case then? I wouldn’t want to have a secondary authentication mechanism so our backend services can access the APIs.

And a secondary question, assuming I will be able to generate that cc token, can I add a custom “sub” claim to the token? I want to do a client\_credentials token with a sub=“cronjob\_123”, this way I can still use this sub in the auditing data (even if it’s a “artificial” user, it will help us to identify where the modification came from).

Thanks

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [November 15, 2021, 9:35pm UTC](https://community.auth0.com/t/create-an-access-token-in-a-cron-job/72871/3 "2021-11-15T21:35:22Z")

</div>

Hi @katlim-br,

Welcome to the Auth0 Community!

> [@katlim-br](#):
>
> Yet if we want to create a client\_credentials token, then according to your documentation, it would not be possible.

Why not? You shouldn’t have trouble getting an access token in whatever script is running in your cron job. Client credentials is most likely the way to go in this scenario. The cron job would be the client/application in this scenario.

> [@katlim-br](#):
>
> And a secondary question, assuming I will be able to generate that cc token, can I add a custom “sub” claim to the token? I want to do a client\_credentials token with a sub=“cronjob\_123”, this way I can still use this sub in the auditing data (even if it’s a “artificial” user, it will help us to identify where the modification came from).

The sub claim is meant to be the identifier of the resource server that is consuming the token. It sounds like this would be the API in your example, not the cron job.

---

<div class="post-metadata">

**Author:** ![katlim-br](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/katlim-br/32/32876_2.png) [@katlim-br](https://community.auth0.com/u/katlim-br)\
**Post date:** [November 15, 2021, 10:06pm UTC](https://community.auth0.com/t/create-an-access-token-in-a-cron-job/72871/4 "2021-11-15T22:06:07Z")

</div>

Yes, after I sent this message, I was able to emit the client\_credentials token. But it is because I had to create a second application marked as M2M, while our main application (UI) would use remain to use Universal Login.

So it is possible.

On the second one, ok, I agree. But to workaround that part, I am sending an additional parameter called my\_param to the oauth/token endpoint, and within an Action for M2M, I add it as a custom claim to the token.

Thanks

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [November 16, 2021, 9:25pm UTC](https://community.auth0.com/t/create-an-access-token-in-a-cron-job/72871/5 "2021-11-16T21:25:12Z")

</div>

Thanks for following up. Let us know if you have any other questions. 😄

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [December 1, 2021, 9:25pm UTC](https://community.auth0.com/t/create-an-access-token-in-a-cron-job/72871/6 "2021-12-01T21:25:59Z")

</div>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
