# How long should the session cookie last?

**URL:** <https://community.hubspot.com/t/how-long-should-the-session-cookie-last/29459>\
**Category:** APIs & Integrations\
**Tags:** free\
**Created:** [December 22, 2020, 9:27am UTC](https://community.hubspot.com/t/how-long-should-the-session-cookie-last/29459 "2020-12-22T09:27:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![catalinsendsms](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/catalinsendsms/32/73373_2.png) [@catalinsendsms](https://community.hubspot.com/u/catalinsendsms)\
**Post date:** [December 22, 2020, 9:27am UTC](https://community.hubspot.com/t/how-long-should-the-session-cookie-last/29459/1 "2020-12-22T09:27:46Z")

</div>

I want to integrate an external app to HubSpot. I was watching [this](https://app.hubspot.com/academy/9039255/tracks/71/593/2968) tutorial and I want to make a session stored in a MySQL database. The video does not specify the max-age of my cookie, so what it should be set to? And when the session cookie expires, how to ask the user to relog?

If I do not need to use this session object, how to identify the different users from my database?

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [December 23, 2020, 4:31pm UTC](https://community.hubspot.com/t/how-long-should-the-session-cookie-last/29459/2 "2020-12-23T16:31:04Z")

</div>

Hey @catalinsendsms ,

Welcome to the Community!

When you speak of session cookie, I am wondering if you are referencing the access token

@himanshurauthan could probably help out here 😀

---

<div class="post-metadata">

**Author:** ![catalinsendsms](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/catalinsendsms/32/73373_2.png) [@catalinsendsms](https://community.hubspot.com/u/catalinsendsms)\
**Post date:** [December 25, 2020, 11:34am UTC](https://community.hubspot.com/t/how-long-should-the-session-cookie-last/29459/3 "2020-12-25T11:34:38Z")

</div>

I messaged him privately

---

<div class="post-metadata">

**Author:** ![himanshurauthan](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/himanshurauthan/32/53076_2.png) [@himanshurauthan](https://community.hubspot.com/u/himanshurauthan)\
**Post date:** [December 29, 2020, 1:38pm UTC](https://community.hubspot.com/t/how-long-should-the-session-cookie-last/29459/4 "2020-12-29T13:38:39Z")

</div>

Hey @catalinsendsms ,

If you are integrating an external app to HubSpot, you would need to fetch an access token and then refresh it automatically.

You can refer to this OAuth API of HubSpot - [Accounts Dashboard | HubSpot](https://legacydocs.hubspot.com/docs/methods/oauth2/oauth2-overview)

Firstly, send a POST request to HubSpot with a data set that would include “grant\_type”, “client\_id”, “client\_secret”, “code” and “redirect\_uri”. From this request, you will get a response which itself will give you the access token expiry.

I hope this helps,  
**Himanshu**
