diff --git a/services/base-service/models/expert/api.js b/services/base-service/models/expert/api.js index 67bec720..a7aa736d 100644 --- a/services/base-service/models/expert/api.js +++ b/services/base-service/models/expert/api.js @@ -37,6 +37,24 @@ router.get('/', (req, res) => { // (as well as the swagger-ui if configured) router.use(openapi); +// Valid users can retrieve an impersonated expert token +router.route( + '/:expertId/impersonation' +).get( + user_can_impersonate, + keycloak_client, + async (req, res,next) => { + try { + let user= await req.keycloak_client.findOneByAttribute(`expertId:${req.params.expertId}`); + console.log('user', user); + let token = await req.keycloak_client.users.impersonation({id:user.id}); + console.log('client', req.keycloak_client.users); + res.status(200).json({token: token}); + } catch (e) { + res.status(e.status || 500).json({error:e.message}); + } + } +); router.patch('/:expertId/availability', // expert_valid_path( // {