Let me back up a bit. Today, the most common mechanism for securing APIs is OAuth2 with Bearer tokens in the form of JWTs. When calling APIs from interactive sessions in a user’s browser, the path of least resistance is to log the user in, stuff their JWT in the browser’s localStorage, and go about your business calling APIs with that JWT. There’s just one problem: security experts say not to do that. That’s because anyone running JavaScript on a page can read any value out of localStorage, so if you treat it as a store for passwords (which, ultimately, a JWT is), you’re opening your customers up to trivially exploitable cross-site scripting attacks. A better approach is to use HTTP cookies to convey this authentication information as 20 years of incremental security enhancements from the browser community have gradually buttressed cookies from cross-site scripting and cross-site request forgery attacks.
SEE ALSO: Serverless and DevOps in 2020 – “Going serverless is a great way of cutting costs”
Possible issues with handling cookies
However, the use of cookies is easier said than done. Developers building microservices routinely fail to incorporate the handling of cookies: those are legacy, browser-related implementation details that we oftentimes assume have nothing to do with the API ecosystem. We prefer to start off building an API with a clean AWS API Gateway Custom Authorizer to validate a Bearer token. We get our API all polished up in production for machine-to-machine calls, and that’s in production for a few months creating shareholder value before someone decides they want to call an API from a browser. Then, someone stumbles over an article telling them not to put JWTs in a browser, and they begin to take steps to rearchitect everything to introduce cookies into the mix. This is not an easy thing to do because cookies are just a fundamentally alien technology to the OAuth flows most of us are building for, so you end up with this odd architectural special case for one particular audience of users.
Source : JAXenter