I have got it working with the following steps:
In the Auth strategy in nuxt.config.js
- Set the refresh path to /oauth/token (I also added a query string, ?refresh to distinguish out from the login path)
- Add this to the header 'Content-Type': 'application/x-www-form-urlencoded'
Here's the code:
refresh: {
url: '/oauth/token?refresh',
method: 'post',
headers: { 'Accept': '*/*','Content-Type': 'application/x-www-form-urlencoded' },
},
I still had problems sending the body in the x-www-form-urlencoded format, so I then created an Axios interceptor plugin to alter the request. This plugin (~/plugins/axios.js) intercepts request made to /oauth/token?refresh and puts the grant type, the refresh token and the client id in the correct format.
Here's the plugin:
var qs = require('qs');
export default function ({ $axios, redirect }) {
$axios.onRequest(config => {
if (config.url == '/oauth/token?refresh') {
const refreshTokenparams = new URLSearchParams(config.data);
const refreshToken params.refresh_token;get('refresh_token');
config.data = qs.stringify({'grant_type': 'refresh_token', 'refresh_token': refreshToken,'client_id':'xxxxx-your-client-id-XXXX'})
}
})
}