# How do SPA access token expires when used against custom API to authenticate

**URL:** <https://community.auth0.com/t/how-do-spa-access-token-expires-when-used-against-custom-api-to-authenticate/78643>\
**Category:** Get Help\
**Created:** [February 21, 2022, 11:29am UTC](https://community.auth0.com/t/how-do-spa-access-token-expires-when-used-against-custom-api-to-authenticate/78643 "2022-02-21T11:29:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karunamay](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/karunamay/32/35180_2.png) [@Karunamay](https://community.auth0.com/u/Karunamay)\
**Post date:** [February 21, 2022, 11:29am UTC](https://community.auth0.com/t/how-do-spa-access-token-expires-when-used-against-custom-api-to-authenticate/78643/1 "2022-02-21T11:29:00Z")

</div>

I am implementing a Django REST API with React. I followed [this](https://auth0.com/docs/quickstart/backend/django/01-authorization) tutorial and fits perfectly as my requirement.

As per the code implementation from the tutorial,

```auto
def jwt_decode_token(token):
    header = jwt.get_unverified_header(token)
    jwks = requests.get(
        settings.SOCIAL_AUTH_AUTH0_DOMAIN + "/.well-known/jwks.json"
    ).json()
    public_key = None
    for jwk in jwks["keys"]:
        if jwk["kid"] == header["kid"]:
            public_key = jwt.algorithms.RSAAlgorithm.from_jwk(json.dumps(jwk))

    if public_key is None:
        raise Exception("Public key not found.")

    issuer = settings.SOCIAL_AUTH_AUTH0_DOMAIN + "/"
    return jwt.decode(
        token,
        public_key,
        audience=settings.SOCIAL_AUTH_AUTH0_AUDIENCE,
        issuer=issuer,
        algorithms=["RS256"],
    )

```

it seems we don’t use the `decode_token` method that the package provided.

All the access tokens got from the SPA using `getAccessTokenSilently()` to authenticate my custom API, apparently, all are working. The function invokes with every new page refresh.

Also, the docs say…

> By default, an access token for a custom API is valid for 86400 seconds (24 hours).

So I assume that’s why both are working. What will be the workaround if I don’t want the last token to remain to validate.

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [February 28, 2022, 10:40pm UTC](https://community.auth0.com/t/how-do-spa-access-token-expires-when-used-against-custom-api-to-authenticate/78643/3 "2022-02-28T22:40:33Z")

</div>

Hi @Karunamay,

Thanks for reaching out to the Auth0 Community!

First, you can manage your access token lifetime settings by going to your [Auth0 Dashboard \> Applications \> APIs](https://manage.auth0.com/#/apis) and clicking on your API. On the settings page, there is the option to configure the **Token Expiration (Seconds)** for your access tokens.

After doing so, you can control when the access token expires.

Note that when using the `getAccessTokenSilently()` method, you are using [silent authentication](https://auth0.com/docs/authenticate/login/configure-silent-authentication) which leverages the use of refresh tokens to refresh the user’s login session without prompting for credentials again.

In your case, using the `getAccessTokenSilently()` method would refresh the expiration of an access token that has access to a specific resource server (API).

> [@Karunamay](#):
>
> What will be the workaround if I don’t want the last token to remain to validate.

Access tokens cannot be invalidated: they are designed to be self-contained, not requiring a check with Auth0 to validate, so there is no way to invalidate them.

For this reason, access tokens should have a short lifetime. [[credit to John Gately’s post]](https://community.auth0.com/t/invalidating-an-access-token-when-user-logs-out/48365/2)

Given that, you could consider setting a low Token Expiration time for the access token while keeping the same refresh token expiration time. This way, you can selectively call silent auth to get a new access token to gain access to the API.

> **[Update Access Token Lifetime](https://auth0.com/docs/secure/tokens/access-tokens/update-access-token-lifetime)**
>
> Describes how to update the access token lifetime for an API using the Auth0 Dashboard.

Hoped this addresses your concerns.

Please feel free to reach out if you have additional questions.

Thank you.

---

<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:** [March 15, 2022, 10:41pm UTC](https://community.auth0.com/t/how-do-spa-access-token-expires-when-used-against-custom-api-to-authenticate/78643/4 "2022-03-15T22:41:17Z")

</div>

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