Hi there,
I am building my very first own application, and it is a challenge!
But, I am not a quitter, so after 2 months struggling with setting up auth0 for my app, I finally come here hoping someone can help me get through this last part now.
I am building an app that works with data from Exact Online. So the user should be able to login to their exact online account and after that they should be able to get data from their Exact Online accounts through the API with the accessToken that Exact Online provided.
I was able to receive the Exact Online accessToken from the identitites part of the user like this in my Node.js express server.js:
app.get('/api/accesstoken', async (req, res) => {
const userID = req.query.userID;
const apiToken = process.env.REACT_APP_AUTH0_MANAGEMENT_API_ACCESS_TOKEN;
const options = {
headers: {
Authorization: `Bearer ${apiToken}`
}
};
try {
const response = await axios.get(`https:[...]/api/v2/users/${encodeURIComponent(userID)}?fields=identities&include_fields=true`, options);
const identities = response.data.identities;
const accessToken = identities[0].access_token;
res.send({ accessToken });
} catch (error) {
res.status(500).send({ error: 'Error fetching user data' });
console.log("error: ", error);
}
I can make a successful API call to Exact Online with this, only after the accessToken expires (10 minutes) it does not get renewed, so I need to logout and login again.
I am a bit stuck on how to handle this, because I can’t seem to receive the RefreshToken that Exact Online provides from the management API, so building a renewal flow into my code is not possible, right? Or am I doing something completely wrong maybe? Is there some workaround for this use case?
Se the big question is, how can I make sure that the user gets a new Exact Online accessToken every 10 minutes for as long as they are active in the app? (So not the auth0 accessToken, because I cannot use that to make API calls to exact online).
I can’t find any documentation about this specific use case and chatGPT 4 also had no clue , so I hope a real expert is around here to help me get through this.
What am I missing, or doing wrong, or: is what I want even possible?
Thank you in advance for taking the time to read my question and see if you can give me some advice.