# Change access token expiration for magic link

**URL:** <https://community.auth0.com/t/change-access-token-expiration-for-magic-link/141601>\
**Category:** Get Help\
**Tags:** identifier-first, login-experience\
**Created:** [August 22, 2024, 10:49pm UTC](https://community.auth0.com/t/change-access-token-expiration-for-magic-link/141601 "2024-08-22T22:49:49Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![wayne.hu](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@wayne.hu](https://community.auth0.com/u/wayne.hu)\
**Post date:** [August 22, 2024, 10:49pm UTC](https://community.auth0.com/t/change-access-token-expiration-for-magic-link/141601/1 "2024-08-22T22:49:49Z")

</div>

Hi, I tried to change the access token expiration in the API settings. However, it works only for username-password login. Is there any way to change it? By default, it is 10 minutes, which is too short for us. Thank you.

---

<div class="post-metadata">

**Author:** ![marcelo.kop](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/marcelo.kop/32/59453_2.png) [@marcelo.kop](https://community.auth0.com/u/marcelo.kop)\
**Post date:** [August 27, 2024, 7:02pm UTC](https://community.auth0.com/t/change-access-token-expiration-for-magic-link/141601/3 "2024-08-27T19:02:26Z")

</div>

Hey guys. I’m experiecing the same issue. Is this a known issue?

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [August 27, 2024, 9:50pm UTC](https://community.auth0.com/t/change-access-token-expiration-for-magic-link/141601/4 "2024-08-27T21:50:10Z")

</div>

Hi there @marcelo.kop and @wayne.hu !

I’m currently unable to reproduce this issue - Just to be clear, you are referring to the resulting access token of logging a user in via a magic link, correct? In my quick test using `auth0-react` + classic universal login + magic link the resulting access token is reflecting the “Maximum Access Token Lifetime” set in API → Access Token Settings:

 ![Screenshot 2024-08-27 at 3.49.29 PM](https://global.discourse-cdn.com/auth0/original/3X/a/7/a764f8834b62208cd0155f5e8e459adc3175163d.png)

---

<div class="post-metadata">

**Author:** ![wayne.hu](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@wayne.hu](https://community.auth0.com/u/wayne.hu)\
**Post date:** [August 27, 2024, 10:08pm UTC](https://community.auth0.com/t/change-access-token-expiration-for-magic-link/141601/5 "2024-08-27T22:08:29Z")

</div>

Hi @ty.frith , thank you for the reply. I am not using the universal login to generate the magic link, instead, my frontend was calling the backend API, which calls /passwordless/start to create the magic link. I changed the `Maximum Access Token Lifetime` to 1 week, but the access\_token returned always 360 seconds.

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [August 27, 2024, 11:00pm UTC](https://community.auth0.com/t/change-access-token-expiration-for-magic-link/141601/6 "2024-08-27T23:00:21Z")

</div>

Thanks for clarifying @wayne.hu !

Are you passing the audience (API Identifier) of the API in `authParams` in the request to `/passwordless/start`?

---

<div class="post-metadata">

**Author:** ![wayne.hu](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@wayne.hu](https://community.auth0.com/u/wayne.hu)\
**Post date:** [August 27, 2024, 11:28pm UTC](https://community.auth0.com/t/change-access-token-expiration-for-magic-link/141601/7 "2024-08-27T23:28:19Z")

</div>

Hi @ty.frith, yes, I attached the code snippet that I was requesting the magic link below, thank you.

```auto
const response = await this.httpService.axiosRef.post(
      `${this.domain}/passwordless/start`,
      {
        client_id: this.clientId,
        client_secret: this.clientSecret,
        connection: 'email',
        email,
        send: 'link',
        authParams: {
          audience: this.audience,
          scope: 'openid email profile offline_access',
          protocol: 'oauth2',
          response_type: 'token',
          redirect_uri: callbackUrl ? callbackUrl : this.callbackUrl,
        },
      },
      {
        headers: {
          authorization: `Bearer ${accessToken}`,
        },
      },
    );

```

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [August 28, 2024, 8:48pm UTC](https://community.auth0.com/t/change-access-token-expiration-for-magic-link/141601/8 "2024-08-28T20:48:07Z")

</div>

Thanks for clarifying!

I am seeing the same thing now, defaulting to 10 minutes 🤔 I’ll dig into this a bit deeper and share my findings.

---

<div class="post-metadata">

**Author:** ![wayne.hu](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@wayne.hu](https://community.auth0.com/u/wayne.hu)\
**Post date:** [September 3, 2024, 7:04pm UTC](https://community.auth0.com/t/change-access-token-expiration-for-magic-link/141601/10 "2024-09-03T19:04:41Z")

</div>

Hi @ty.frith, any updates on this issue? Thank you.

---

<div class="post-metadata">

**Author:** ![marcelo.kop](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/marcelo.kop/32/59453_2.png) [@marcelo.kop](https://community.auth0.com/u/marcelo.kop)\
**Post date:** [September 11, 2024, 2:32pm UTC](https://community.auth0.com/t/change-access-token-expiration-for-magic-link/141601/11 "2024-09-11T14:32:05Z")

</div>

Hey guys. I’m glad you were able to reproduce the issue. Any updates on this? Let us know if we can help even further @ty.frith

---

<div class="post-metadata">

**Author:** ![marcelo.kop](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/marcelo.kop/32/59453_2.png) [@marcelo.kop](https://community.auth0.com/u/marcelo.kop)\
**Post date:** [September 16, 2024, 6:40pm UTC](https://community.auth0.com/t/change-access-token-expiration-for-magic-link/141601/12 "2024-09-16T18:40:00Z")

</div>

@ty.frith @wayne.hu Do you guys happen to know if this is a dev environment issue only? I want to move my app to prod and I’m afraid I might need to change the authentication provider from Auth0 to Clerk or something because of this issue.

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [September 16, 2024, 10:16pm UTC](https://community.auth0.com/t/change-access-token-expiration-for-magic-link/141601/13 "2024-09-16T22:16:06Z")

</div>

Hey there @wayne.hu @marcelo.kop sorry for the delayed response here! I’ve opened up a discussion internally to hopefully gain some clarity on this behavior. I will provide an update here as soon as I have more information myself.

Thanks a bunch for your patience and understanding!

---

<div class="post-metadata">

**Author:** ![marcelo.kop](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/marcelo.kop/32/59453_2.png) [@marcelo.kop](https://community.auth0.com/u/marcelo.kop)\
**Post date:** [September 16, 2024, 11:45pm UTC](https://community.auth0.com/t/change-access-token-expiration-for-magic-link/141601/14 "2024-09-16T23:45:48Z")

</div>

Thanks @ty.frith. Do you know a workaround we can use? I would like to keep users logged in for maybe one week. I don’t think Magic Links have `refresh_token` and I’m not sure how to exchange that token for a longer one without a huge lift in the backend

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [September 17, 2024, 11:31pm UTC](https://community.auth0.com/t/change-access-token-expiration-for-magic-link/141601/15 "2024-09-17T23:31:47Z")

</div>

Hey there @marcelo.kop !

What type of application are you using? The max access token lifetime in general is 24 hours (86400) seconds. Because you are using `response_type: token` you are kicking off an [implicit flow](https://auth0.com/docs/authenticate/login/oidc-conformant-authentication/oidc-adoption-implicit-flow) which doesn’t allow for the use of refresh tokens. The implicit flow access token lifetime can be found below the “Maximum Access Token Lifetime”:

 ![Screenshot 2024-09-17 at 5.25.43 PM](https://global.discourse-cdn.com/auth0/original/3X/2/2/2281a3e053aeb57ad5044cb81fbf6b6a378439ff.png)

If you want to request refresh tokens, you will need change the original request to `response_type: code` - Upon clicking the the magic link, the user will be redirected to your application at which point you will need to use the `code` against the token endpoint to perform the token exchange:

```POST
Content-Type: application/json

{
  "grant_type": "authorization_code",
  "client_id": "5sFZ3Auwiu445554ddjzSqcG",
  "client_secret": "K7xqpXdFZ3NyoBMwjRF-QT0SN345sdfg56g2aTUmPzigGh",
  "code": "{authorization_code_from_redirect}",
  "redirect_uri": "https://your-app.com/callback",
  "scope": "openid profile email offline_access"
}

At this point you should get both access and refresh tokens assuming your application has the Refresh Token grant type enabled and the API registered in Auth0 (which you are using as audience) has "Allow Offline Access" toggled to on.
```

---

<div class="post-metadata">

**Author:** ![wayne.hu](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@wayne.hu](https://community.auth0.com/u/wayne.hu)\
**Post date:** [September 18, 2024, 2:14am UTC](https://community.auth0.com/t/change-access-token-expiration-for-magic-link/141601/16 "2024-09-18T02:14:34Z")

</div>

Thank you @ty.frith.  
Just want to confirm: `response_type: token` is kicking off an `implicit flow`, and `response_type: code` is `oauth2` flow, right? And both are working for the Magic Link?

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [September 18, 2024, 1:53pm UTC](https://community.auth0.com/t/change-access-token-expiration-for-magic-link/141601/17 "2024-09-18T13:53:18Z")

</div>

Happy to help at @wayne.hu ! Both flows are technically part of the OAuth 2 framework, however yes `response_type: token` kicks off the implicit flow whereas `response_type: code` kicks off the [authorization code flow](https://auth0.com/docs/get-started/authentication-and-authorization-flow/authorization-code-flow).

---

<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:** [October 2, 2024, 1:53pm UTC](https://community.auth0.com/t/change-access-token-expiration-for-magic-link/141601/18 "2024-10-02T13:53:30Z")

</div>

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