This is an automated email from the ASF dual-hosted git repository.

nealsun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/helix.git


The following commit(s) were added to refs/heads/master by this push:
     new 236d8b75b Send Identity Token from helix-front to helix-rest (#2259)
236d8b75b is described below

commit 236d8b75b7de175b553d72664d71932d9f65f028
Author: helix-bot <[email protected]>
AuthorDate: Wed Nov 2 17:43:13 2022 -0700

    Send Identity Token from helix-front to helix-rest (#2259)
    
    If an identity token source is configured.
---
 helix-front/server/app.ts               | 14 ++++++++++++++
 helix-front/server/controllers/helix.ts |  8 +++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/helix-front/server/app.ts b/helix-front/server/app.ts
index 4f3ff816f..ff873a232 100644
--- a/helix-front/server/app.ts
+++ b/helix-front/server/app.ts
@@ -32,6 +32,20 @@ app.use(
 
 app.use(morgan('dev'));
 
+app.use((req, res, next) => {
+  const {
+    headers: { cookie },
+  } = req;
+  if (cookie) {
+    const values = cookie.split(';').reduce((res, item) => {
+      const data = item.trim().split('=');
+      return { ...res, [data[0]]: data[1] };
+    }, {});
+    res.locals.cookie = values;
+  } else res.locals.cookie = {};
+  next();
+});
+
 setRoutes(app);
 
 app.get('/*', function (req, res) {
diff --git a/helix-front/server/controllers/helix.ts 
b/helix-front/server/controllers/helix.ts
index 4d70262af..8d2507f8c 100644
--- a/helix-front/server/controllers/helix.ts
+++ b/helix-front/server/controllers/helix.ts
@@ -2,7 +2,7 @@ import { Request, Response, Router } from 'express';
 
 import * as request from 'request';
 
-import { HELIX_ENDPOINTS } from '../config';
+import { HELIX_ENDPOINTS, IDENTITY_TOKEN_SOURCE } from '../config';
 import { HelixUserRequest } from './d';
 
 export class HelixCtrl {
@@ -50,6 +50,12 @@ export class HelixCtrl {
           'Helix-User': user,
         },
       };
+
+      if (IDENTITY_TOKEN_SOURCE) {
+        options.headers['Identity-Token'] =
+          res.locals.cookie['helixui_identity.token'];
+      }
+
       request[method](options, (error, response, body) => {
         if (error) {
           res.status(response?.statusCode || 500).send(error);

Reply via email to