Skip to content

Commit 9d49b3f

Browse files
committed
add middleware that sets sap-client header based on scope
1 parent 8c64603 commit 9d49b3f

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

approuter/my-ext.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,27 @@ module.exports = {
77
},
88
],
99
beforeRequestHandler: [
10+
{
11+
path: "/sap",
12+
handler: function sapClientMiddleware(req, res, next) {
13+
if (req.user && req.user.scopes && Array.isArray(req.user.scopes)) {
14+
const scopePrefix = "HTML5UserAPIforCF!t5585.Client";
15+
const matchingScope = req.user.scopes.find(
16+
(scope) =>
17+
typeof scope === "string" && scope.startsWith(scopePrefix)
18+
);
19+
20+
if (matchingScope) {
21+
const clientNumber = matchingScope.substring(scopePrefix.length);
22+
if (clientNumber) {
23+
req.headers["sap-client"] = clientNumber;
24+
console.log("Set sap-client header to: %s", clientNumber);
25+
}
26+
}
27+
}
28+
return next();
29+
},
30+
},
1031
{
1132
path: "/services/userapi/currentUser",
1233
handler: function myMiddleware(req, res, next) {

0 commit comments

Comments
 (0)