is it possible to do a jwt authentication? I want to be able to renew the token when it expires
on request failure I call this function, but not work
if(getUsersApi.data[0].error == 'token expired' || ts_Token.value == null){
Promise.resolve(generateToken.trigger()).then(data => {
ts_Token.setValue(data[0].token)
getUsersApi.trigger()
})
}
ben
June 25, 2021, 3:07am
2
Hi @leosantosx !
How is your resource authentication currently set up? How do you provision the tokens?
Hi @ben
/ POST https://example/authenticate
body:
{
"username": "value",
"password": "value",
}
response:
{
"token": "value",
"expiresIn": "value"
}
/ GET https://example/list-users
headers:
{
"token": "value",
"Content-Type": "application/json"
}
response: list all users or message: "token expired"
Template:
how do i revalidate the token?
ben
June 25, 2021, 2:58pm
4
I see! If you define these requests inside the resource setup page - Retool will handle the authentication + refresh requests. There is an example of how to set this up in the Custom API Authentication docs
@ben Do you have an example (template)?
I'm not succeeding
ben
June 25, 2021, 3:52pm
6
@leosantosx can you share how you currently have this set up?
ben
June 25, 2021, 4:22pm
8
it looks like you are setting the authentication inside the base request. But you need to add your token request to the auth section of the resource: