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 511164e13 fix cross-domain cookie-setting bug (#2295)
511164e13 is described below

commit 511164e13c069e91d808d34ac9f7b8c696e08826
Author: helix-bot <[email protected]>
AuthorDate: Mon Nov 28 18:59:21 2022 -0800

    fix cross-domain cookie-setting bug (#2295)
    
    Ensure that cookies are properly stored on the client.
---
 helix-front/server/controllers/user.ts | 18 ++++++++++++------
 helix-front/src/app/app.component.ts   | 32 --------------------------------
 2 files changed, 12 insertions(+), 38 deletions(-)

diff --git a/helix-front/server/controllers/user.ts 
b/helix-front/server/controllers/user.ts
index 6527a2bcc..10ec4e98f 100644
--- a/helix-front/server/controllers/user.ts
+++ b/helix-front/server/controllers/user.ts
@@ -10,6 +10,7 @@ import {
   SSL,
 } from '../config';
 import { HelixRequest, HelixRequestOptions } from './d';
+import { TOKEN_EXPIRATION_KEY, TOKEN_RESPONSE_KEY } from '../config';
 
 export class UserCtrl {
   constructor(router: Router) {
@@ -131,12 +132,17 @@ export class UserCtrl {
                           const parsedBody = JSON.parse(body);
                           req.session.isAdmin = isInAdminGroup;
                           req.session.identityToken = parsedBody;
-                          //
-                          // TODO possibly also send identity token
-                          // TODO parsedBody to the client as a cookie
-                          // TODO Github issue #2236
-                          //
-                          res.set('Identity-Token-Payload', body);
+
+                          const cookieName = 'helixui_identity.token';
+                          const cookieValue =
+                            parsedBody.value[TOKEN_RESPONSE_KEY];
+                          const cookieExpiresDate = new Date(
+                            parsedBody.value[TOKEN_EXPIRATION_KEY]
+                          );
+                          const cookieOptions = {
+                            expires: cookieExpiresDate,
+                          };
+                          res.cookie(cookieName, cookieValue, cookieOptions);
                           res.json(isInAdminGroup);
 
                           return parsedBody;
diff --git a/helix-front/src/app/app.component.ts 
b/helix-front/src/app/app.component.ts
index 9da3dd7ab..d48b0b77c 100644
--- a/helix-front/src/app/app.component.ts
+++ b/helix-front/src/app/app.component.ts
@@ -14,11 +14,6 @@ import { MatDialog } from '@angular/material/dialog';
 import { UserService } from './core/user.service';
 import { InputDialogComponent } from 
'./shared/dialog/input-dialog/input-dialog.component';
 import { HelperService } from './shared/helper.service';
-import {
-  TOKEN_RESPONSE_KEY,
-  TOKEN_EXPIRATION_KEY,
-  IDENTITY_TOKEN_SOURCE,
-} from '../../server/config';
 
 @Component({
   selector: 'hi-root',
@@ -98,33 +93,6 @@ export class AppComponent implements OnInit {
                     );
                   }
 
-                  //
-                  // set cookie with Identity Token
-                  // if an Identity Token Source is configured
-                  //
-                  if (IDENTITY_TOKEN_SOURCE && TOKEN_RESPONSE_KEY) {
-                    const identityTokenPayload = loginResponse.headers.get(
-                      'Identity-Token-Payload'
-                    );
-
-                    const parsedIdentityTokenPayload =
-                      JSON.parse(identityTokenPayload);
-
-                    const cookie = {
-                      name: 'helixui_identity.token',
-                      value:
-                        parsedIdentityTokenPayload.value[TOKEN_RESPONSE_KEY],
-                      expirationDate: new Date(
-                        parsedIdentityTokenPayload.value[TOKEN_EXPIRATION_KEY]
-                      ).toUTCString(),
-                    };
-
-                    const cookieString = `${cookie.name}=${
-                      cookie.value || ''
-                    }; expires=${cookie.expirationDate}; path=/; domain=`;
-                    document.cookie = cookieString;
-                  }
-
                   this.currentUser = this.service.getCurrentUser();
                 },
                 (error) => {

Reply via email to