REST token check on middleware layer

Hi,

I have a challenge. My goal is to check rest-api token on middleware service and find related UserSession. For now i’m making http request “userInfo” via rest-api to check token and get User ID, then I’m creating new UserSession for this User ID. But this is “костыли” (horrible solution).

Will be glad to get ideas.

Hi,
Try to use com.haulmont.addon.restapi.rest.ServerTokenStore bean and its getSessionInfoByTokenValue() method:

RestUserSessionInfo getSessionInfoByTokenValue(String tokenValue);
1 Like

Thanks so much. It’s a working solution.

During more deep testing I’ve found one thing:
getSessionInfoByTokenValue works good only till application reboot. After reboot this method don’t find session by token any more.
I have enabled option cuba.rest.storeTokensInDb, so my REST tokens are stored in DB and I can use them event after app reboot. It works when I’m testing REST methods via Postman.