# What is the purpose of a client secret?

**URL:** <https://community.auth0.com/t/what-is-the-purpose-of-a-client-secret/82313>\
**Category:** Get Help\
**Tags:** auth0\
**Created:** [April 25, 2022, 9:27am UTC](https://community.auth0.com/t/what-is-the-purpose-of-a-client-secret/82313 "2022-04-25T09:27:20Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![lukashavrlant](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/lukashavrlant/32/36742_2.png) [@lukashavrlant](https://community.auth0.com/u/lukashavrlant)\
**Post date:** [April 25, 2022, 9:27am UTC](https://community.auth0.com/t/what-is-the-purpose-of-a-client-secret/82313/1 "2022-04-25T09:27:20Z")

</div>

Hi, we want to let our customers programatically sign to our app using their username/password. I figured out the [http://auth0.com/oauth/grant-type/password-realm](http://auth0.com/oauth/grant-type/password-realm) grant type is way to go. In order to fetch the tokens, one has to send request such as this one:

```auto
curl --location --request POST 'https://tenant.auth0.com/oauth/token' \
--header 'content-type: application/json' \
--data-raw '{
    "grant_type": "http://auth0.com/oauth/grant-type/password-realm",
    "client_id": "client id",
    "client_secret": "secret",
    "username": "username",
    "password": "password",
    "realm": "Username-Password-Authentication",
    "scope": "openid email"
}'

```

Is it dangerous to share client\_secret to our customers? What harm can they do to us with the client secret? The client secret is not used for signing the ID/access tokens, right? (we use RS256 encryption) If we create a new application for each customer, would it be safe enough? (so they don’t share the secret) Is there a better way to allow our customers programatically log in using their username/password?

---

<div class="post-metadata">

**Author:** ![jeff0](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jeff0/32/30027_2.png) [@jeff0](https://community.auth0.com/u/jeff0)\
**Post date:** [April 25, 2022, 1:44pm UTC](https://community.auth0.com/t/what-is-the-purpose-of-a-client-secret/82313/2 "2022-04-25T13:44:33Z")

</div>

hi @lukashavrlant

Welcome to Auth0 Community !!!

Even though Auth0 provides the ability to pass on username and password for authentication but it is def not recommended. This posses a security risk of logging creds. To pass on username/password your client needs to capture the creds first which means the app capturing the username/password could log credentials before passing it on to Auth0.

The recommendation here would be to use universal login flow (redirection). Your scenario looks like to be B2B. So your customers \> users will use your app which will authenticate via Auth0. Is that the case ? If so, then you could use [organizations](https://auth0.com/docs/manage-users/organizations).

Thanks  
Jeff

---

<div class="post-metadata">

**Author:** ![lukashavrlant](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/lukashavrlant/32/36742_2.png) [@lukashavrlant](https://community.auth0.com/u/lukashavrlant)\
**Post date:** [April 25, 2022, 2:16pm UTC](https://community.auth0.com/t/what-is-the-purpose-of-a-client-secret/82313/3 "2022-04-25T14:16:59Z")

</div>

Hi, thank you for your reply 🙂

The use case is this: we have a web application (SPA) which talks to our API (resource server). In this case, we use the standard universal login flow as you recommended. User is redirected to [tenant.auth0.com](http://tenant.auth0.com), logs in and is redirected back to our web. This works fine.

But, some users actually want to write a CLI script that does something with our API. No browser involved, just some CLI script or CRON job that communicates with our resource server. Hence we want to let them fetch ID and access token from Auth0, which they can use when communicating with our API. Hence the password-realm example I posted above.

What is the best way to achieve this if not the password-realm?

---

<div class="post-metadata">

**Author:** ![jeff0](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jeff0/32/30027_2.png) [@jeff0](https://community.auth0.com/u/jeff0)\
**Post date:** [April 25, 2022, 2:35pm UTC](https://community.auth0.com/t/what-is-the-purpose-of-a-client-secret/82313/4 "2022-04-25T14:35:29Z")

</div>

Hi @lukashavrlant

In your case, it is recommended to use Machine 2 Machine flow. here are some references:

> **[Call Your API from a Machine-to-Machine App](https://auth0.com/docs/microsites/call-api/call-api-m2m-app)**
>
> Everything you need to know to call your API from your machine-to-machine (M2M) app

> **[Using Machine to Machine (M2M) Authorization](https://auth0.com/blog/using-m2m-authorization/)**
>
> How to set up non-interactive apps using the client credentials grant and Auth0 to perform IoT device, CLI tool, and more machine to mach...

Hope it helps

regards  
Jeff

---

<div class="post-metadata">

**Author:** ![lukashavrlant](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/lukashavrlant/32/36742_2.png) [@lukashavrlant](https://community.auth0.com/u/lukashavrlant)\
**Post date:** [April 25, 2022, 2:43pm UTC](https://community.auth0.com/t/what-is-the-purpose-of-a-client-secret/82313/5 "2022-04-25T14:43:55Z")

</div>

Is it possible to also get ID token with this flow?

---

<div class="post-metadata">

**Author:** ![jeff0](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jeff0/32/30027_2.png) [@jeff0](https://community.auth0.com/u/jeff0)\
**Post date:** [April 25, 2022, 3:05pm UTC](https://community.auth0.com/t/what-is-the-purpose-of-a-client-secret/82313/6 "2022-04-25T15:05:53Z")

</div>

Hi @lukashavrlant

No, Id tokens are meant for authentication of a user not for a CLI or machine tasks

Can the CLI or client apps pass user\_id or whatever you are after from client apps as POST payload to your API’s?

Thanks  
Jeff

---

<div class="post-metadata">

**Author:** ![lukashavrlant](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/lukashavrlant/32/36742_2.png) [@lukashavrlant](https://community.auth0.com/u/lukashavrlant)\
**Post date:** [April 25, 2022, 4:14pm UTC](https://community.auth0.com/t/what-is-the-purpose-of-a-client-secret/82313/7 "2022-04-25T16:14:59Z")

</div>

Ok, to make things more complicated, I’ll describe the whole flow. In the SPA, we redirect the user to [tenant.auth0.com](http://tenant.auth0.com), they log in and they are redirected back to our app. At this point, we take the auth0 ID token, we send it to “our authorization server” and based on user\_id from the ID token we generate whole new access token signed by our secret. This access token is used to access our resource servers. Our resource servers do not accept any auth0 tokens. We use just the ID token for the authentication part. Both auth0 tokens are basically forgotten at this moment. That is why we need our users to be able to fetch ID token from auth0 so they can send it to “our authorization server” and exchange it for the final access token. We can use other flow but this would not require adding any functionality to our apps.

---

<div class="post-metadata">

**Author:** ![lukashavrlant](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/lukashavrlant/32/36742_2.png) [@lukashavrlant](https://community.auth0.com/u/lukashavrlant)\
**Post date:** [April 26, 2022, 8:40am UTC](https://community.auth0.com/t/what-is-the-purpose-of-a-client-secret/82313/8 "2022-04-26T08:40:39Z")

</div>

If we go back to the previous question: is it safe to share the client secret to our customers? Can they do something with it other than logging in via username/password? Something dangerous…?

---

<div class="post-metadata">

**Author:** ![jeff0](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jeff0/32/30027_2.png) [@jeff0](https://community.auth0.com/u/jeff0)\
**Post date:** [April 26, 2022, 9:49am UTC](https://community.auth0.com/t/what-is-the-purpose-of-a-client-secret/82313/9 "2022-04-26T09:49:47Z")

</div>

Hi @lukashavrlant

If users are getting redirected back to your app why the customers need to have client secrets ? I am trying to understand how the customers will get users passwords to get token from password grant ? Are they capturing the username/password from their users ?

---

<div class="post-metadata">

**Author:** ![lukashavrlant](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/lukashavrlant/32/36742_2.png) [@lukashavrlant](https://community.auth0.com/u/lukashavrlant)\
**Post date:** [April 26, 2022, 10:30am UTC](https://community.auth0.com/t/what-is-the-purpose-of-a-client-secret/82313/10 "2022-04-26T10:30:21Z")

</div>

I am talking about the use case when CLI or CRON is involved. If we don’t use machine2machine flow but we use the password-realm instead, they have to send username, password and client secret (as I wrote in the first post here: [What is the purpose of a client secret?](https://community.auth0.com/t/what-is-the-purpose-of-a-client-secret/82313))

So my question is: if we share the client secret to our customers, can they do any harm with it to us? I understand that the password-realm is not recommended but it seems it’s the only way unless we want to rewrite parts of our application (which we don’t want to for now).

In other words: we want to allow our users to get ID token via [http://auth0.com/oauth/grant-type/password-realm](http://auth0.com/oauth/grant-type/password-realm) using their username/password and I’m asking how dangerous is to share a client secret with them?

---

<div class="post-metadata">

**Author:** ![jeff0](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jeff0/32/30027_2.png) [@jeff0](https://community.auth0.com/u/jeff0)\
**Post date:** [April 26, 2022, 1:59pm UTC](https://community.auth0.com/t/what-is-the-purpose-of-a-client-secret/82313/11 "2022-04-26T13:59:33Z")

</div>

hi @lukashavrlant

It is fine to create a separate application for your client (per client) and share your client’s secret with your customers as long as you:

- Restrict their applications/clients to connections only as required.
- Only give scopes/permissions as required.
- Make sure their applications have **NO** access to management API otherwise they can do admin tasks on your tenant.

Hope this helps

Regards  
Jeff

---

<div class="post-metadata">

**Author:** ![lukashavrlant](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/lukashavrlant/32/36742_2.png) [@lukashavrlant](https://community.auth0.com/u/lukashavrlant)\
**Post date:** [April 27, 2022, 6:28am UTC](https://community.auth0.com/t/what-is-the-purpose-of-a-client-secret/82313/12 "2022-04-27T06:28:35Z")

</div>

Thank you, that was helpful! 🙂

---

<div class="post-metadata">

**Author:** ![lukashavrlant](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/lukashavrlant/32/36742_2.png) [@lukashavrlant](https://community.auth0.com/u/lukashavrlant)\
**Post date:** [April 27, 2022, 8:09am UTC](https://community.auth0.com/t/what-is-the-purpose-of-a-client-secret/82313/13 "2022-04-27T08:09:33Z")

</div>

One final question: how can we make sure the application has no access to management API? What should we disable or what should we check to be absolutely sure?
