# How can i get access token to auth my custom api

**URL:** <https://community.auth0.com/t/how-can-i-get-access-token-to-auth-my-custom-api/61148>\
**Category:** Get Help\
**Created:** [April 15, 2021, 11:03am UTC](https://community.auth0.com/t/how-can-i-get-access-token-to-auth-my-custom-api/61148 "2021-04-15T11:03:26Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![pandeysumit832](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/pandeysumit832/32/24787_2.png) [@pandeysumit832](https://community.auth0.com/u/pandeysumit832)\
**Post date:** [April 15, 2021, 11:03am UTC](https://community.auth0.com/t/how-can-i-get-access-token-to-auth-my-custom-api/61148/1 "2021-04-15T11:03:26Z")

</div>

How can i get access token to auth my custom api like getAccessTokenSilenty() does in useAuth0()

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [April 15, 2021, 11:25am UTC](https://community.auth0.com/t/how-can-i-get-access-token-to-auth-my-custom-api/61148/3 "2021-04-15T11:25:10Z")

</div>

Hi @pandeysumit832,

Do you need the Access Token for your custom API in your frontend app? If so, you can use the identifier of your API that is registered with Auth0 and use this as the audience in your frontend app.

---

<div class="post-metadata">

**Author:** ![pandeysumit832](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/pandeysumit832/32/24787_2.png) [@pandeysumit832](https://community.auth0.com/u/pandeysumit832)\
**Post date:** [April 15, 2021, 4:35pm UTC](https://community.auth0.com/t/how-can-i-get-access-token-to-auth-my-custom-api/61148/4 "2021-04-15T16:35:47Z")

</div>

yeah doing the same but the issue is i want to store it somewhere so that i don’t need to access it again and again but the problem is that every time my react app runs the function is to get called is there any way i can check that the token is valid or not then call the api again if not valid

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [April 15, 2021, 5:05pm UTC](https://community.auth0.com/t/how-can-i-get-access-token-to-auth-my-custom-api/61148/5 "2021-04-15T17:05:12Z")

</div>

Are you using the Auth0 Rect SDK? [Auth0 React SDK Quickstarts: Login](https://auth0.com/docs/quickstart/spa/react/01-login)

The SDK will handle the caching for you so that your app does not make unnecessary auth requests.

Here is an article on token storage using the SDK: [Token Storage](https://auth0.com/docs/tokens/token-storage#single-page-app-scenarios)

---

<div class="post-metadata">

**Author:** ![pandeysumit832](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/pandeysumit832/32/24787_2.png) [@pandeysumit832](https://community.auth0.com/u/pandeysumit832)\
**Post date:** [April 15, 2021, 5:06pm UTC](https://community.auth0.com/t/how-can-i-get-access-token-to-auth-my-custom-api/61148/6 "2021-04-15T17:06:11Z")

</div>

nope bcoz i had to use my own dedicated login page i am using normal webauth package

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [April 15, 2021, 5:56pm UTC](https://community.auth0.com/t/how-can-i-get-access-token-to-auth-my-custom-api/61148/7 "2021-04-15T17:56:40Z")

</div>

I see! In that case, I’d recommend taking a look at this migration guide to compare `auth0.js` with`auth0-spa-js`: [Migrate from Auth0.js to the Auth0 Single Page App SDK](https://auth0.com/docs/libraries/auth0-single-page-app-sdk/migrate-from-auth0-js-to-the-auth0-single-page-app-sdk#auth0-js)

The equivalent implementation for `getAccessTokenSilenty()` in `auth0-js` would be `checkSession`:

```auto
auth0.checkSession({}, function(err, authResult) {
    // Authentication tokens or error
  });

```

---

<div class="post-metadata">

**Author:** ![pandeysumit832](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/pandeysumit832/32/24787_2.png) [@pandeysumit832](https://community.auth0.com/u/pandeysumit832)\
**Post date:** [April 15, 2021, 6:32pm UTC](https://community.auth0.com/t/how-can-i-get-access-token-to-auth-my-custom-api/61148/8 "2021-04-15T18:32:30Z")

</div>

can i use my own dedicated login page

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [April 15, 2021, 6:39pm UTC](https://community.auth0.com/t/how-can-i-get-access-token-to-auth-my-custom-api/61148/9 "2021-04-15T18:39:22Z")

</div>

Universal Login is recommended for security and other reasons, however, you can set up an embedded login instead of Universal Login. When using an embedded login, it’s best to use a Custom Domain so that you don’t run into cross-origin authentication issues. Here is more info about setting up an embedded login:

> **[Embedded Login](https://auth0.com/docs/authenticate/login/embedded-login)**
>
> Describes Auth0 Embedded Login used to log users directly into your application, transmitting credentials to the Auth0 server.

---

<div class="post-metadata">

**Author:** ![pandeysumit832](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/pandeysumit832/32/24787_2.png) [@pandeysumit832](https://community.auth0.com/u/pandeysumit832)\
**Post date:** [April 15, 2021, 6:40pm UTC](https://community.auth0.com/t/how-can-i-get-access-token-to-auth-my-custom-api/61148/10 "2021-04-15T18:40:56Z")

</div>

I tired check session dosent work for me

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [April 15, 2021, 6:49pm UTC](https://community.auth0.com/t/how-can-i-get-access-token-to-auth-my-custom-api/61148/11 "2021-04-15T18:49:30Z")

</div>

Here are some ready-to-go examples of `auth0-js`:

> **[auth0.js/example at master · auth0/auth0.js](https://github.com/auth0/auth0.js/tree/master/example)**
>
> master/example

Let me know if you are seeing a specific error when you try these out!

---

<div class="post-metadata">

**Author:** ![pandeysumit832](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/pandeysumit832/32/24787_2.png) [@pandeysumit832](https://community.auth0.com/u/pandeysumit832)\
**Post date:** [April 15, 2021, 6:53pm UTC](https://community.auth0.com/t/how-can-i-get-access-token-to-auth-my-custom-api/61148/12 "2021-04-15T18:53:14Z")

</div>

i m passing my custom aud to check session but its saying undefined

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [April 15, 2021, 6:58pm UTC](https://community.auth0.com/t/how-can-i-get-access-token-to-auth-my-custom-api/61148/13 "2021-04-15T18:58:57Z")

</div>

Would you mind sharing a code snippet?

Here is the full documentation for the `checkSession` method: [JSDoc: Global](https://auth0.github.io/auth0.js/global.html#checkSession)

---

<div class="post-metadata">

**Author:** ![pandeysumit832](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/pandeysumit832/32/24787_2.png) [@pandeysumit832](https://community.auth0.com/u/pandeysumit832)\
**Post date:** [April 15, 2021, 7:03pm UTC](https://community.auth0.com/t/how-can-i-get-access-token-to-auth-my-custom-api/61148/14 "2021-04-15T19:03:07Z")

</div>

```auto
const token = () => {

        webAuth.checkSession(

            {

                audience: https://quickstart/api,

                scope: "read:message",

            },

            function (err, authResult) {

                if (err) {

                    return err;

                }

                return authResult;

            }

        );

    };

```

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [April 15, 2021, 7:50pm UTC](https://community.auth0.com/t/how-can-i-get-access-token-to-auth-my-custom-api/61148/15 "2021-04-15T19:50:51Z")

</div>

It looks like you need quotation marks around `https://quickstart/api`:

```auto
audience: "https://quickstart/api",

```

Would you mind sharing the specific error message? Also, if you look in your tenant logs, are you seeing any errors?

---

<div class="post-metadata">

**Author:** ![pandeysumit832](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/pandeysumit832/32/24787_2.png) [@pandeysumit832](https://community.auth0.com/u/pandeysumit832)\
**Post date:** [April 15, 2021, 8:02pm UTC](https://community.auth0.com/t/how-can-i-get-access-token-to-auth-my-custom-api/61148/16 "2021-04-15T20:02:20Z")

</div>

Yeup I tried doing that no errors when I m trying to console log it return undefined

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [April 15, 2021, 8:04pm UTC](https://community.auth0.com/t/how-can-i-get-access-token-to-auth-my-custom-api/61148/17 "2021-04-15T20:04:31Z")

</div>

Just to clarify, is it the `token` var that is logging as undefined?

---

<div class="post-metadata">

**Author:** ![pandeysumit832](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/pandeysumit832/32/24787_2.png) [@pandeysumit832](https://community.auth0.com/u/pandeysumit832)\
**Post date:** [April 15, 2021, 8:12pm UTC](https://community.auth0.com/t/how-can-i-get-access-token-to-auth-my-custom-api/61148/18 "2021-04-15T20:12:16Z")

</div>

there is an error in the logs saying consent required

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [April 16, 2021, 11:48am UTC](https://community.auth0.com/t/how-can-i-get-access-token-to-auth-my-custom-api/61148/19 "2021-04-16T11:48:18Z")

</div>

Based on the docs, it looks like this error will be thrown when running the app on localhost when the following scopes are not requested: `openid profile email`

Are you requesting these scopes?

[https://auth0.com/docs/libraries/auth0js#scope](https://auth0.com/docs/libraries/auth0js#scope)

---

<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:** [May 1, 2021, 11:48am UTC](https://community.auth0.com/t/how-can-i-get-access-token-to-auth-my-custom-api/61148/20 "2021-05-01T11:48:21Z")

</div>

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