<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/best-practices-for-storing-access-tokens-in-the-browser-y0w9frdpk" -->

---
title: Best Practices for Storing Access Tokens in the Browser
description: Web applications often use OAuth 2.0 for data security, which involves storing access tokens. This piece examines various browser storage solutions like local...
canonical: https://daily.dev/posts/best-practices-for-storing-access-tokens-in-the-browser-y0w9frdpk
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Best Practices for Storing Access Tokens in the Browser | daily.dev
og:description: Web applications often use OAuth 2.0 for data security, which involves storing access tokens. This piece examines various browser storage solutions like local...
og:url: https://daily.dev/posts/best-practices-for-storing-access-tokens-in-the-browser-y0w9frdpk
og:image: https://api.daily.dev/og/posts/y0W9fRdpk.png
og:image:alt: Best Practices for Storing Access Tokens in the Browser
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Best Practices for Storing Access Tokens in the Browser

**[Community Picks](https://daily.dev/sources/community)** · 17 min read · 159 upvotes · 5 comments

## Summary

Web applications often use OAuth 2.0 for data security, which involves storing access tokens. This piece examines various browser storage solutions like local storage, session storage, and cookies, highlighting their vulnerabilities to XSS and CSRF attacks. The token handler pattern is recommended for enhancing security, suggesting encrypted tokens stored in secure cookies and managed by backend components.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://curity.medium.com/best-practices-for-storing-access-tokens-in-the-browser-6b3d515d9814>

## Community discussion

Top comments from developers on daily.dev.

**@gianlucabove** · 1 upvotes

> Very useful!

**@magnussantus** · 1 upvotes

> the problem with using cookie is that if you set it to secure and http-only.  JS cannot read it and decode it. So it won't work clientside if you have components on your page that should be shown depending to which roles you are in. I might have understood it wrong here. In that case my appologies

**@stratisderm** · 0 upvotes

> Great post with clear instructions.

**@herloncosta** · 0 upvotes

> Nice post! Thanks!!

**@plleonart** · 0 upvotes

> Really useful and interesting! Thanks

---

Tags: [#security](https://daily.dev/tags/security), [#webdev](https://daily.dev/tags/webdev), [#javascript](https://daily.dev/tags/javascript), [#oauth](https://daily.dev/tags/oauth), [#web-security](https://daily.dev/tags/web-security)

[View this post on daily.dev](https://daily.dev/posts/best-practices-for-storing-access-tokens-in-the-browser-y0w9frdpk)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Best Practices for Storing Access Tokens in the Browser","url":"https://daily.dev/posts/best-practices-for-storing-access-tokens-in-the-browser-y0w9frdpk","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/best-practices-for-storing-access-tokens-in-the-browser-y0w9frdpk"},"datePublished":"2024-10-08T10:20:50.881Z","dateModified":"2024-12-11T12:46:18.614Z","description":"Web applications often use OAuth 2.0 for data security, which involves storing access tokens. This piece examines various browser storage solutions like local...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/8cfe8d96fa64b38b9885034cc9e9f0b4?_a=AQAEuiZ","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/8cfe8d96fa64b38b9885034cc9e9f0b4?_a=AQAEuiZ","isAccessibleForFree":true,"articleSection":"Community Picks","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Community Picks","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1655817725/logos/community","url":"https://daily.dev/sources/community"},"commentCount":5,"discussionUrl":"https://daily.dev/posts/best-practices-for-storing-access-tokens-in-the-browser-y0w9frdpk","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":159},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":5}],"keywords":"security,webdev,javascript,oauth,web-security","timeRequired":"PT17M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Community Picks","item":"https://daily.dev/sources/community"},{"@type":"ListItem","position":3,"name":"Best Practices for Storing Access Tokens in the Browser"}]}
{"@context":"https://schema.org","@type":"WebPage","@id":"https://daily.dev/posts/best-practices-for-storing-access-tokens-in-the-browser-y0w9frdpk","comment":[{"@type":"Comment","text":"Very useful!","datePublished":"2024-12-31T11:56:34.156Z","url":"https://daily.dev/posts/y0W9fRdpk#c-TVZBauwwC","author":{"@type":"Person","name":"Gianluca Bove","url":"https://daily.dev/gianlucabove","image":"https://media.daily.dev/image/upload/s--rCFYQUO8--/f_auto/v1735298072/avatars/avatar_75flGx7PMGH3CjgFDRC18"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1}},{"@type":"Comment","text":"the problem with using cookie is that if you set it to secure and http-only.  JS cannot read it and decode it. So it won’t work clientside if you have components on your page that should be shown depending to which roles you are in. I might have understood it wrong here. In that case my appologies","datePublished":"2025-01-08T03:17:41.737Z","url":"https://daily.dev/posts/y0W9fRdpk#c-J37H4XFpW","author":{"@type":"Person","name":"Gilberto","url":"https://daily.dev/magnussantus","image":"https://media.daily.dev/image/upload/s--xS57HZ1n--/f_auto/v1733766006/avatars/avatar_rTrY7Tg7hpEuvr6XaX2wr"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1}},{"@type":"Comment","text":"Great post with clear instructions.","datePublished":"2024-11-21T08:49:45.698Z","url":"https://daily.dev/posts/y0W9fRdpk#c-lfKMNLqVC","author":{"@type":"Person","name":"Stratis Dermanoutsos","url":"https://daily.dev/stratisderm","image":"https://media.daily.dev/image/upload/s--jK4_tSAa--/f_auto/v1763060433/avatars/avatar_hZjp22d684nHP4c9Hislh?_a=BAMAK+ZW0"}},{"@type":"Comment","text":"Nice post! Thanks!!","datePublished":"2024-10-09T11:45:17.494Z","url":"https://daily.dev/posts/y0W9fRdpk#c-9ZqDco7gI","author":{"@type":"Person","name":"Herlon Costa","url":"https://daily.dev/herloncosta","image":"https://lh3.googleusercontent.com/a/ACg8ocI26qlLwCi-czfeUEP4Ygw6voxl5My-nOcv7m-BhAGLxE2NQK83=s96-c"}},{"@type":"Comment","text":"Really useful and interesting! Thanks","datePublished":"2024-12-13T06:55:38.226Z","url":"https://daily.dev/posts/y0W9fRdpk#c-ZZkYyPLVt","author":{"@type":"Person","name":"Pascal Lleonart","url":"https://daily.dev/plleonart","image":"https://avatars.githubusercontent.com/u/179757618?v=4"}}]}
```

