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

Add auth to routes #492

Merged
merged 6 commits into from
Feb 16, 2021
Merged
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 packages/ui5-middleware-cfdestination/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ server:
- name: ui5-middleware-cfdestination
afterMiddleware: compression
configuration:
authenticationMethod: "none" # "none" || "route", default: "none"
allowServices: false # allows sap services like SAP IoT to be used
debug: true
port: 1091
xsappJson: "xs-app.json"
Expand Down
12 changes: 6 additions & 6 deletions packages/ui5-middleware-cfdestination/lib/cfdestination.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ module.exports = function ({ resources, options }) {
const xsappConfig = JSON.parse(fs.readFileSync(options.configuration.xsappJson, 'utf8'));
const xsappPath = options.configuration.xsappJson.replace("xs-app.json", "");

// the embedded approuter (the one that runs locally) will ignore all auth mechanisms.
// Even when xsappConfig.authenticationMethod = "route" and only define the routes,
// the approuter will try to read the env var during startup - and fail if they are missing
xsappConfig.authenticationMethod = "none";
// the default auth mechanism is set to none but the user can pass an auth method using the options
xsappConfig.authenticationMethod = options.configuration.authenticationMethod || "none";
vobu marked this conversation as resolved.
Show resolved Hide resolved

let regExes = [];
xsappConfig.routes = xsappConfig.routes.filter((route) => !route.localDir && !route.service); //ignore routes that point to web apps as they are already hosted by the ui5 tooling
xsappConfig.routes = xsappConfig.routes
.filter((route) => !route.localDir && (options.configuration.allowServices || !route.service)); //ignore routes that point to web apps as they are already hosted by the ui5 tooling

xsappConfig.routes.forEach(route => {
route.authenticationType = "none";
/* Authentication type should come from route or be set to none as default */
route.authenticationType = route.authenticationType || "none";
// ignore /-redirects (e.g. "^/(.*)"
// a source declaration such as "^/backend/(.*)$" is needed
if (route.source.match(/.*\/.*\/.*/)) {
Expand Down