Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expire formio #279

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions deployment/docker/docker-compose-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions deployment/docker/docker-compose-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions deployment/docker/sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -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-----#
Expand Down
1 change: 1 addition & 0 deletions forms-flow-forms/docker-compose-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions forms-flow-forms/src/authentication/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions forms-flow-web/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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

Expand Down
1 change: 1 addition & 0 deletions forms-flow-web/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions forms-flow-web/public/config/config.sample.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}

};
1 change: 1 addition & 0 deletions forms-flow-web/sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,4 @@ USER_ACCESS_PERMISSIONS={"accessAllowApplications":false,"accessAllowSubmissions

#JWT SECRETE KEY
#FORMIO_JWT_SECRET=--- change me now ---
#FORMIO_JWT_EXPIRE=240
3 changes: 3 additions & 0 deletions forms-flow-web/src/constants/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 19 additions & 2 deletions forms-flow-web/src/services/UserService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -61,6 +62,7 @@ const initKeycloak = (store, ...rest) => {
// onAuthenticatedCallback();
done(null, KeycloakData);
refreshToken(store);
formioRefreshToken();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to Give the User Role Info as Well

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move Refresh Interval Calls to authenticate Formio after first token is created

} else {
doLogout();
}
Expand All @@ -84,6 +86,16 @@ const refreshToken = (store) => {
}, 6000);
}

// formio token refresh
let refreshFormioInterval;

const formioRefreshToken =()=>{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would only refresh token as anonymous Role

refreshFormioInterval = setInterval(()=>{
const user = ANONYMOUS_USER;
const roles = [ANONYMOUS_ID];
authenticateFormio(user, roles);
},FORMIO_JWT_EXPIRE)
}

/**
* Logout function
Expand All @@ -92,6 +104,7 @@ const userLogout = () => {
localStorage.clear();
sessionStorage.clear();
clearInterval(refreshInterval);
clearInterval(refreshFormioInterval);
doLogout();
};

Expand Down Expand Up @@ -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);
Expand Down