---
title: "Discussion on \"Introduction to REST API Authentication Methods\" | Hashnode"
description: "Discussion on \"Introduction to REST API Authentication Methods\". Hello devs! In this article, I'll be discussing some common ways to authenticate your API as a way to protect your routes from users that shouldn't access them.\nWhy should I protect my routes?\nCertain routes such as your user's profile page or the ad..."
url: "https://hashnode.com/posts/introduction-to-rest-api-authentication-methods/5f40655b98f2d769410814b9"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Introduction to REST API Authentication Methods](https://blog.lo-victoria.com/introduction-to-rest-api-authentication-methods?utm_source=hashnode&utm_medium=feed)

Hello devs! In this article, I'll be discussing some common ways to authenticate your API as a way to protect your routes from users that shouldn't access them. Why should I protect my routes? Certain routes such as your user's profile page or the ad...

Aug 22, 2020 · 7 min read · blog.lo-victoria.com  
Updated Jul 22, 2024  
Read the article

-   [#rest-api](https://hashnode.com/tag/rest-api)
-   [#authentication](https://hashnode.com/tag/authentication)
-   [#jwt](https://hashnode.com/tag/jwt)
-   [#oauth](https://hashnode.com/tag/oauth)
-   [#authorization](https://hashnode.com/tag/authorization)

## Written by

[Victoria Lo](https://hashnode.com/@victoria)

@victoria · Singapore

  
[View profile](https://hashnode.com/@victoria)

A nerd in books, tea, games and software.

I'm a solutions engineer lead, GitHub Star, Director of WomenDevsSG, and co founder of ragTech. I work at the intersection of tech, systems, and leadership, and this blog is where I share my journey through all three. Expect honest reflections, real experiences, and thoughts that are still forming rather than polished career advice.

## Responses 3

Markdown supported · ⌘↵ to post

[Ader Chox](https://hashnode.com/@aderchox)

[Feb 27, 2023](https://hashnode.com/posts/introduction-to-rest-api-authentication-methods/5f40655b98f2d769410814b9/comment/63fc6deaa13f5e02f6799d6a)

Thank you, but Never store passwords in JWTs, this is bad practice and better removed from the article.

[Ader Chox](https://hashnode.com/@aderchox)

[Feb 27, 2023](https://hashnode.com/posts/introduction-to-rest-api-authentication-methods/5f40655b98f2d769410814b9/comment/63fc6deaa13f5e02f6799d6a#reply-63fc6e7ea13f5e02f6799d96)

It will be as vulnerable as basic authentication in that case.

[Victoria Lo](https://hashnode.com/@victoria)

[Feb 27, 2023](https://hashnode.com/posts/introduction-to-rest-api-authentication-methods/5f40655b98f2d769410814b9/comment/63fc6deaa13f5e02f6799d6a#reply-63fc79cb42967b0d40d38d38)

Thanks for the feedback [Ader Chox](https://hashnode.com/@aderchox). Apologies if the article was unclear but yes, we do not store passwords in JWTs. I'll update the article so it will be more coherent.

[Chigbogu Orji](https://hashnode.com/@chigboguorji)

[Aug 22, 2020](https://hashnode.com/posts/introduction-to-rest-api-authentication-methods/5f40655b98f2d769410814b9/comment/5f40c64898f2d76941081658)

What a great article, I am currently working on a project that needs authentication... I find this useful.

[Victoria Lo](https://hashnode.com/@victoria)

[Aug 22, 2020](https://hashnode.com/posts/introduction-to-rest-api-authentication-methods/5f40655b98f2d769410814b9/comment/5f40c64898f2d76941081658#reply-5f4137d87d6e4770b16f8b6d)

Thanks a lot! :)

[Xu Chunyang](https://hashnode.com/@xuchunyang)

[Aug 22, 2020](https://hashnode.com/posts/introduction-to-rest-api-authentication-methods/5f40655b98f2d769410814b9/comment/5f409ed898f2d76941081574)

Hi, I'm a newbee to web dev. I am not sure how website keeps user login. The method I can implement is storing user's username & plain password in the localStorage, then whenever the user opens my website, I use javascript to send their user name & password to login in them automtiaclly. I heard user's plain password should not be stored anywhere, so this is a bad idea, however, I have not figured out how the token/session id works, i.e., how to create the token, how to verify it, where to store it, how to revoke it, how to prevert user from modifying it etc. I want to learn how to implement these before trying others' existing frameworks.

`generateAccessToken` returns a different token for the same payload each time, right? and It is done by converting `{ expiresIn: '1800s' }` to the actual timestamp or purely hash function "magic"?

Can external javascript read localStroage and cookie? e.g., I store user's plain password in localStroage and I includes a external foo (say jquery) library, can the code in the foo library read the password?

[Victoria Lo](https://hashnode.com/@victoria)

[Aug 22, 2020](https://hashnode.com/posts/introduction-to-rest-api-authentication-methods/5f40655b98f2d769410814b9/comment/5f409ed898f2d76941081574#reply-5f4137bb1b16b970904c11be)

Hi Chunyang, thanks for the question.

In terms of storing JWT tokens, yes you are right. Don't ever store it in localStorage. The secure way to store in on the server-side memory so only your code can access it and not any external JavaScript.

Another way is to use HTTPS secured cookies or `httpOnly` cookies. More details [here](https://owasp.org/www-community/HttpOnly). More about cookies in general [here](https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies). Hope that helps!
