Refreshing access tokens with axios interceptors

Axios interceptor functions can be thought of like action filters or middleware in ASP.NET MVC. They are invoked on every single request that we make using axios, and we can hook into the request both before it has run and after. This makes them ideal for our refresh token requirements, as we can check every response that we get back from an API request and perform some custom logic if we detect an authentication failure.

In this case, we'll be looking for 401 response status codes, checking whether we have a refresh token to use, and then attempting to obtain a new access token using the new API endpoint we created earlier on. If we get one, we re-trigger the original request that failed, ...

Get ASP.NET Core 2 and Vue.js now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.