diff --git a/deployment/docker/docker-compose-linux.yml b/deployment/docker/docker-compose-linux.yml index c701a09c7a..025e378933 100644 --- a/deployment/docker/docker-compose-linux.yml +++ b/deployment/docker/docker-compose-linux.yml @@ -105,6 +105,8 @@ services: ROOT_PASSWORD: ${FORMIO_ROOT_PASSWORD:-changeme} FORMIO_DOMAIN: ${FORMIO_DEFAULT_PROJECT_URL} FORMIO_JWT_SECRET: ${FORMIO_JWT_SECRET:---- change me now ---} + FORMIO_JWT_EXPIRE: ${FORMIO_JWT_EXPIRE:-240} + stdin_open: true # -i tty: true # -t diff --git a/deployment/docker/docker-compose-windows.yml b/deployment/docker/docker-compose-windows.yml index a772146964..c31cb19255 100644 --- a/deployment/docker/docker-compose-windows.yml +++ b/deployment/docker/docker-compose-windows.yml @@ -105,6 +105,8 @@ services: ROOT_PASSWORD: ${FORMIO_ROOT_PASSWORD:-changeme} FORMIO_DOMAIN: ${FORMIO_DEFAULT_PROJECT_URL} FORMIO_JWT_SECRET: ${FORMIO_JWT_SECRET:---- change me now ---} + FORMIO_JWT_EXPIRE: ${FORMIO_JWT_EXPIRE:-240} + stdin_open: true # -i tty: true # -t diff --git a/deployment/docker/sample.env b/deployment/docker/sample.env index 02361734b6..05721560e4 100644 --- a/deployment/docker/sample.env +++ b/deployment/docker/sample.env @@ -14,6 +14,7 @@ ##URL of forms-flow-forms FORMIO_DEFAULT_PROJECT_URL=http://{your-ip-address}:3001 #FORMIO_JWT_SECRET=--- change me now --- +#FORMIO_JWT_EXPIRE=240 #-----Environment Variables for FormIO Datastore-----# diff --git a/forms-flow-forms/docker-compose-windows.yml b/forms-flow-forms/docker-compose-windows.yml index 34a87e88f9..e2b523675f 100644 --- a/forms-flow-forms/docker-compose-windows.yml +++ b/forms-flow-forms/docker-compose-windows.yml @@ -55,6 +55,7 @@ services: ROOT_PASSWORD: ${FORMIO_ROOT_PASSWORD:-changeme} FORMIO_DOMAIN: ${FORMIO_DEFAULT_PROJECT_URL} FORMIO_JWT_SECRET: ${FORMIO_JWT_SECRET:---- change me now ---} + FORMIO_JWT_EXPIRE: ${FORMIO_JWT_EXPIRE:-240} stdin_open: true # -i tty: true # -t diff --git a/forms-flow-forms/src/authentication/index.js b/forms-flow-forms/src/authentication/index.js index 57f312db44..04e59f3442 100644 --- a/forms-flow-forms/src/authentication/index.js +++ b/forms-flow-forms/src/authentication/index.js @@ -46,10 +46,8 @@ module.exports = (router) => { } = jwtConfig; // changed the secret and expire to the env - - - return jwt.sign(payload, customSecret ||process.env.FORMIO_JWT_SECRET||secret , { - expiresIn: (expireTime ||240) * 60, + return jwt.sign(payload, customSecret ||process.env.FORMIO_JWT_SECRET||secret , { + expiresIn: (expireTime || Number(process.env.FORMIO_JWT_EXPIRE) ||240) * 60, }); }; // Number(process.env.FORMIO_JWT_EXPIRE)|| todo diff --git a/forms-flow-web/Dockerfile b/forms-flow-web/Dockerfile index 28c6bbd9d2..88a5ae7ca8 100644 --- a/forms-flow-web/Dockerfile +++ b/forms-flow-web/Dockerfile @@ -25,6 +25,7 @@ ARG REACT_APP_APPLICATION_NAME ARG REACT_APP_USER_ACCESS_PERMISSIONS ARG REACT_APP_WEB_BASE_CUSTOM_URL ARG REACT_APP_FORMIO_JWT_SECRET +ARG REACT_APP_FORMIO_JWT_EXPIRE ENV NODE_ENV ${NODE_ENV} ENV REACT_APP_CLIENT_ROLE ${REACT_APP_CLIENT_ROLE} @@ -47,6 +48,8 @@ ENV REACT_APP_APPLICATION_NAME ${REACT_APP_APPLICATION_NAME} ENV REACT_APP_USER_ACCESS_PERMISSIONS ${REACT_APP_USER_ACCESS_PERMISSIONS} ENV REACT_APP_WEB_BASE_CUSTOM_URL ${REACT_APP_WEB_BASE_CUSTOM_URL} ENV REACT_APP_FORMIO_JWT_SECRET ${REACT_APP_FORMIO_JWT_SECRET} +ENV REACT_APP_FORMIO_JWT_EXPIRE ${REACT_APP_FORMIO_JWT_EXPIRE} + # add `/app/node_modules/.bin` to $PATH ENV PATH /forms-flow-web/app/node_modules/.bin:$PATH diff --git a/forms-flow-web/docker-compose.yml b/forms-flow-web/docker-compose.yml index ed492f7a8f..ccd8a0b778 100644 --- a/forms-flow-web/docker-compose.yml +++ b/forms-flow-web/docker-compose.yml @@ -29,6 +29,7 @@ services: - REACT_APP_USER_ACCESS_PERMISSIONS=${USER_ACCESS_PERMISSIONS} - REACT_APP_WEB_BASE_CUSTOM_URL=${WEB_BASE_CUSTOM_URL} - REACT_APP_FORMIO_JWT_SECRET=${FORMIO_JWT_SECRET:---- change me now ---} + - REACT_APP_FORMIO_EXPIRE=${FORMIO_JWT_EXPIRE:-240} ports: - "3000:8080" tty: true diff --git a/forms-flow-web/public/config/config.sample.js b/forms-flow-web/public/config/config.sample.js index 655c6053fb..d5df7f88f3 100644 --- a/forms-flow-web/public/config/config.sample.js +++ b/forms-flow-web/public/config/config.sample.js @@ -46,6 +46,7 @@ window["_env_"] = { //custom url REACT_APP_WEB_BASE_CUSTOM_URL:"Custom URL", REACT_APP_FORMIO_JWT_SECRET:"Jwt secret key", + REACT_APP_FORMIO_JWT_EXPIRE:"Jwt Expire time", REACT_APP_USER_ACCESS_PERMISSIONS:{accessAllowApplications:false, accessAllowSubmissions:false} }; diff --git a/forms-flow-web/sample.env b/forms-flow-web/sample.env index 128bab0fcb..412507bddf 100644 --- a/forms-flow-web/sample.env +++ b/forms-flow-web/sample.env @@ -52,3 +52,4 @@ USER_ACCESS_PERMISSIONS={"accessAllowApplications":false,"accessAllowSubmissions #JWT SECRETE KEY #FORMIO_JWT_SECRET=--- change me now --- +#FORMIO_JWT_EXPIRE=240 \ No newline at end of file diff --git a/forms-flow-web/src/constants/constants.js b/forms-flow-web/src/constants/constants.js index be2d5bf273..23fbb1137f 100644 --- a/forms-flow-web/src/constants/constants.js +++ b/forms-flow-web/src/constants/constants.js @@ -35,6 +35,9 @@ export const ANONYMOUS_USER = "anonymous"; export const FORMIO_JWT_SECRET = (window._env_ && window._env_.REACT_APP_FORMIO_JWT_SECRET) || process.env.REACT_APP_FORMIO_JWT_SECRET || "--- change me now ---"; +export const FORMIO_JWT_EXPIRE = + ((window._env_ && window._env_.REACT_APP_FORMIO_JWT_EXPIRE) || process.env.REACT_APP_FORMIO_JWT_EXPIRE || 240) * 60; + export const USER_RESOURCE_FORM_ID = (window._env_ && window._env_.REACT_APP_USER_RESOURCE_FORM_ID) || process.env.REACT_APP_USER_RESOURCE_FORM_ID; diff --git a/forms-flow-web/src/services/UserService.js b/forms-flow-web/src/services/UserService.js index 7e8a6a8fbe..ff2e34632e 100644 --- a/forms-flow-web/src/services/UserService.js +++ b/forms-flow-web/src/services/UserService.js @@ -5,7 +5,8 @@ import { Keycloak_Client, ANONYMOUS_USER, ANONYMOUS_ID, - FORMIO_JWT_SECRET + FORMIO_JWT_SECRET, + FORMIO_JWT_EXPIRE } from "../constants/constants"; import { setUserRole, @@ -61,6 +62,7 @@ const initKeycloak = (store, ...rest) => { // onAuthenticatedCallback(); done(null, KeycloakData); refreshToken(store); + formioRefreshToken(); } else { doLogout(); } @@ -84,6 +86,16 @@ const refreshToken = (store) => { }, 6000); } +// formio token refresh +let refreshFormioInterval; + +const formioRefreshToken =()=>{ + refreshFormioInterval = setInterval(()=>{ + const user = ANONYMOUS_USER; + const roles = [ANONYMOUS_ID]; + authenticateFormio(user, roles); + },FORMIO_JWT_EXPIRE) +} /** * Logout function @@ -92,6 +104,7 @@ const userLogout = () => { localStorage.clear(); sessionStorage.clear(); clearInterval(refreshInterval); + clearInterval(refreshFormioInterval); doLogout(); }; @@ -133,7 +146,11 @@ const authenticateFormio = (user, roles) => { roles: roles, }, }, - FORMIO_JWT_SECRET + + FORMIO_JWT_SECRET, + { + expiresIn:FORMIO_JWT_EXPIRE + } ); // TODO Move JWT secret key to COME From ENV //TODO remove this token from local Storage on logout and try to move to redux store as well localStorage.setItem("formioToken", FORMIO_TOKEN);