# How to set grant\_type to client\_credentials in @auth0/@auth0-react SDK?

**URL:** <https://community.auth0.com/t/how-to-set-grant-type-to-client-credentials-in-auth0-auth0-react-sdk/103504>\
**Category:** Get Help\
**Tags:** clients, management-api\
**Created:** [March 28, 2023, 11:01am UTC](https://community.auth0.com/t/how-to-set-grant-type-to-client-credentials-in-auth0-auth0-react-sdk/103504 "2023-03-28T11:01:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![leslie](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/leslie/32/45792_2.png) [@leslie](https://community.auth0.com/u/leslie)\
**Post date:** [March 28, 2023, 11:01am UTC](https://community.auth0.com/t/how-to-set-grant-type-to-client-credentials-in-auth0-auth0-react-sdk/103504/1 "2023-03-28T11:01:08Z")

</div>

For some reason, I want to set `grant_type` to `client_credentials` when call `/oauth/token ` endpoint.  
I’m not sure if this requirement can be achieved in a single page application. At least I didn’t find a way to set grant\_type in auth0 react SDK.

I have seen this section doc: [Get Management API Access Tokens for Production](https://auth0.com/docs/secure/tokens/access-tokens/get-management-api-access-tokens-for-production?_gl=1*jbbz9g*rollup_ga*MTA3MDE1MDM3MC4xNjY4NzY3ODM3*rollup_ga_F1G3E656YZ*MTY4MDAwNDI0Ni40LjEuMTY4MDAwNTk0Ni42MC4wLjA.&_ga=2.209190866.1596332233.1680004246-1070150370.1668767837)

I also wonder if we can directly set the value of is\_first\_party directly in the Auth0 Management Dashboard([https://manage.auth0.com/dashboard](https://manage.auth0.com/dashboard)).

And here is my config (code source： auth0 react SDK example code)

```auto
const deferred = (() => {
  const props = {};
  props.promise = new Promise((resolve) => (props.resolve = resolve));
  return props;
})();

export const getAccessToken = async () => {
  const getToken = await deferred.promise;
  return getToken();
};

// Please see https://auth0.github.io/auth0-react/interfaces/Auth0ProviderOptions.html
// for a full list of the available properties on the provider
const config = getConfig();

const providerConfig = {
  domain: config.domain,
  clientId: config.clientId,
  audience: config.audience,
  redirectUri: window.location.origin,
  useRefreshTokens: true,
  onRedirectCallback,
};

ReactDOM.render(
  <Auth0Provider {...providerConfig}>
    <Auth0Context.Consumer>
      {({ getAccessTokenSilently }) => {
        deferred.resolve(getAccessTokenSilently);
        return <App />;
      }}
    </Auth0Context.Consumer>
  </Auth0Provider>,
  document.getElementById('root')
);

```

---

<div class="post-metadata">

**Author:** ![peter.fernandez](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/peter.fernandez/32/45477_2.png) [@peter.fernandez](https://community.auth0.com/u/peter.fernandez)\
**Post date:** [March 29, 2023, 9:15am UTC](https://community.auth0.com/t/how-to-set-grant-type-to-client-credentials-in-auth0-auth0-react-sdk/103504/3 "2023-03-29T09:15:02Z")

</div>

Hi @leslie 👋

> For some reason, I want to set `grant_type` to `client_credentials` when call `/oauth/token ` endpoint.  
> I’m not sure if this requirement can be achieved in a single page application. At least I didn’t find a way to set grant\_type in auth0 react SDK.

The `client_credentials` grant is typically executed from a backend context, where something like a _service_ - or some other **machine-level** executable - is requesting a token for a **machine-level** (i.e. **non-user** ) API call. For `client_credentials` grant a `client_secret` is required, and forms part of the machine-level credentials. As such, the backend context should be secure, so use of `client_credentials` is **not** recommended from an (insecure) client context; typically, Auth0 will guard against use in a client-side (e.g. React) context by only permitting the grant on a `Machine to Machine` type application.

> I have seen this section doc: [Get Management API Access Tokens for Production](https://auth0.com/docs/secure/tokens/access-tokens/get-management-api-access-tokens-for-production?_gl=1*jbbz9g*rollup_ga*MTA3MDE1MDM3MC4xNjY4NzY3ODM3*rollup_ga_F1G3E656YZ*MTY4MDAwNDI0Ni40LjEuMTY4MDAwNTk0Ni42MC4wLjA.&_ga=2.209190866.1596332233.1680004246-1070150370.1668767837)

For the Auth0 Management API, you will indeed require an Access Token allocated using the `client_credentials` grant, so typically won’t be able to - and shouldn’t - do this in a client-side (e.g. React) context.

> I also wonder if we can directly set the value of is\_first\_party directly in the Auth0 Management Dashboard([https://manage.auth0.com/dashboard](https://manage.auth0.com/dashboard)).

By default, all Applications defined via the Auth0 Dashboard are _First Party_ (see [here](https://auth0.com/docs/get-started/applications/confidential-and-public-applications/first-party-and-third-party-applications#first-party-applications) for more details). If you are trying to bypass the consent page for your API, then in the settings on the API definition you’ll see an option toggle to `Allow Skipping User Consent` - which you can enable for _First Party_ applications (see [here](https://auth0.com/docs/get-started/apis/api-settings#token-settings) for more details).

Note: This toggle allows skipping consent for _verifiable_ first party applications. If your application is hosted on `localhost`, Auth0 has no reason to believe that it’s truly first party - as a user may maliciously - or without their knowledge - run any application on `localhost`. If you want to skip the consent page during development, you can typically setup a mapping in your `hosts` file to map `localhost` to `app.local` for example.

---

<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 12, 2024, 8:06am UTC](https://community.auth0.com/t/how-to-set-grant-type-to-client-credentials-in-auth0-auth0-react-sdk/103504/4 "2024-12-12T08:06:59Z")

</div>

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