authx - If using auto-login, then use a redirect to hide the `?_authx=...` gunk
authorTim Otten <totten@civicrm.org>
Tue, 23 Feb 2021 10:50:39 +0000 (02:50 -0800)
committerTim Otten <totten@civicrm.org>
Tue, 2 Mar 2021 19:37:53 +0000 (11:37 -0800)
ext/authx/authx.php
ext/authx/tests/phpunit/Civi/Authx/AllFlowsTest.php

index 21224dfb9c14068df3762a778376184104e57a06..faaec6cef05c8bb172852c623fd7cc545757a12e 100644 (file)
@@ -22,7 +22,12 @@ Civi::dispatcher()->addListener('civi.invoke.auth', function($e) {
     }
     elseif (!empty($params['_authxSes'])) {
       (new \Civi\Authx\Authenticator('auto'))->auth($e, $params['_authx'], TRUE);
-      _authx_redact(['_authx', '_authxSes']);
+      if ($_SERVER['REQUEST_METHOD'] === 'GET') {
+        _authx_reload(implode('/', $e->args), $_SERVER['QUERY_STRING']);
+      }
+      else {
+        _authx_redact(['_authx', '_authxSes']);
+      }
     }
     else {
       (new \Civi\Authx\Authenticator('param'))->auth($e, $params['_authx']);
@@ -52,6 +57,23 @@ function _authx_redact(array $keys) {
   }
 }
 
+/**
+ * Reload the current page-view.
+ *
+ * @param string $route
+ * @param string $queryString
+ */
+function _authx_reload($route, $queryString) {
+  parse_str($queryString, $query);
+  foreach (array_keys($query) as $key) {
+    if (CRM_Utils_String::startsWith($key, '_authx')) {
+      unset($query[$key]);
+    }
+  }
+  $url = CRM_Utils_System::url($route, $query, TRUE, NULL, FALSE, CRM_Core_Config::singleton()->userSystem->isFrontEndPage());
+  CRM_Utils_System::redirect($url);
+}
+
 /**
  * Implements hook_civicrm_config().
  *
index ae3e6a164f920db09f9a0b5915e6e65d1174ebc5..eb6eff39b77bd8614f92780c201da1a80947ff31 100644 (file)
@@ -253,8 +253,9 @@ class AllFlowsTest extends \PHPUnit\Framework\TestCase implements EndToEndInterf
     $request = $this->applyAuth($this->requestMyContact(), $credType, $flowType, $this->getDemoCID());
 
     \Civi::settings()->set("authx_{$flowType}_cred", [$credType]);
+    $this->assertEquals(0, $cookieJar->count());
     $response = $http->send($request);
-    $this->assertHasCookies($response);
+    $this->assertTrue($cookieJar->count() >= 1);
     $this->assertMyContact($this->getDemoCID(), $this->getDemoUID(), $response);
 
     // FIXME: Assert that re-using cookies yields correct result.