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

AuthX - Extended authentication support (portable and router-friendly) #19590

Merged
merged 25 commits into from
Mar 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e09616f
CRM_Core_Invoker - Emit authorization event
totten Feb 12, 2021
bb1d197
CRM_Core_Session - Add option 'useFakeSession()' for stateless requests
totten Feb 13, 2021
7946d65
authx - Generate skeleton
totten Feb 12, 2021
9e99ef4
authx - Draft README and info.xml
totten Feb 12, 2021
7b61742
authx - Declare settings for allowed flows and credentials
totten Feb 12, 2021
aef9279
authx - Add page to check identity ('civicrm/authx/id')
totten Feb 12, 2021
7547226
authx - Add the AllFlowsTest
totten Feb 12, 2021
3a429e3
authx - Primary implementation, including Drupal 7 and WordPress
totten Feb 12, 2021
b9cbf1a
authx - Support JWT credentials
totten Feb 16, 2021
d0528c9
authx - Support login/logout flow
totten Feb 16, 2021
682f265
(REF) AllFlowsTest - Misc cleanup
totten Feb 17, 2021
1abd042
authx - Support Backdrop users+sessions
totten Feb 16, 2021
17211d2
authx - Support Drupal 8 users+sessions
totten Feb 16, 2021
6ea9067
authx - Support Joomla users+sessions
totten Feb 16, 2021
5395178
authx - Make it safe to load the 'authx.settings.php' file multiple t…
totten Feb 20, 2021
b482c19
distmaker - Add authx to tarball
totten Feb 17, 2021
9c818a6
AllFlowsTest - Add test for checking contact+user vs contact-only
totten Feb 19, 2021
93628c7
AllFlowsTest - Add cases with multiple identities from the same browser
totten Feb 19, 2021
17802aa
(REF) AllFlowsTest - Cleanup helper signature
totten Feb 20, 2021
8f35c19
AllFlowsTest - When executing on a new deployment, ensure demo user h…
totten Feb 20, 2021
1c61351
authx - Support Joomla users+sessions - Prevent leaks among stateless…
totten Feb 20, 2021
17df918
authx - The "already logged in" check should be less sensitive to int…
totten Feb 23, 2021
a196e83
authx - If using auto-login, then use a redirect to hide the `?_authx…
totten Feb 23, 2021
8a01c43
(REF) Authenticator - Extract field $authxUf
totten Feb 26, 2021
0ecb5a5
(REF) authx - Reorganize internal methods to use an auth-request object
totten Feb 26, 2021
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.use-civicrm-setup
/ext/*
!/ext/afform
!/ext/authx
!/ext/sequentialcreditnotes
!/ext/flexmailer
!/ext/eventcart
Expand Down
1 change: 1 addition & 0 deletions CRM/Core/Invoke.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public static function _invoke($args) {
// may exit
self::hackMenuRebuild($args);
self::init($args);
Civi::dispatcher()->dispatch('civi.invoke.auth', \Civi\Core\Event\GenericHookEvent::create(['args' => $args]));
$item = self::getItem($args);
return self::runItem($item);
}
Expand Down
33 changes: 33 additions & 0 deletions CRM/Core/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,39 @@ public static function &singleton() {
return self::$_singleton;
}

/**
* Replace the session object with a fake session.
*/
public static function useFakeSession() {
self::$_singleton = new class() extends CRM_Core_Session {

public function initialize($isRead = FALSE) {
if ($isRead) {
return;
}

if (!isset($this->_session)) {
$this->_session = [];
}

if (!isset($this->_session[$this->_key]) || !is_array($this->_session[$this->_key])) {
$this->_session[$this->_key] = [];
}
}

public function isEmpty() {
return empty($this->_session);
}

};
self::$_singleton->_session = NULL;
// This is not a revocable proposition. Should survive, even with things 'System.flush'.
if (!defined('_CIVICRM_FAKE_SESSION')) {
define('_CIVICRM_FAKE_SESSION', TRUE);
}
return self::$_singleton;
}

/**
* Creates an array in the session.
*
Expand Down
4 changes: 3 additions & 1 deletion CRM/Utils/System/Drupal.php
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,9 @@ public function onCiviExit() {
if (!defined('MAINTENANCE_MODE') || MAINTENANCE_MODE != 'update') {
module_invoke_all('exit');
}
drupal_session_commit();
if (!defined('_CIVICRM_FAKE_SESSION')) {
drupal_session_commit();
}
}
}

Expand Down
1 change: 1 addition & 0 deletions distmaker/dists/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ function dm_core_exts() {
echo ext/ewaysingle
echo ext/financialacls
echo ext/afform
echo ext/authx
echo ext/greenwich
echo ext/contributioncancelactions
echo ext/oauth-client
Expand Down
44 changes: 44 additions & 0 deletions ext/authx/CRM/Authx/Page/AJAX.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

use CRM_Authx_ExtensionUtil as E;

class CRM_Authx_Page_AJAX {

/**
* Identify the current user.
*
* GET /civicrm/authx/id
*/
public static function getId() {
$authxUf = _authx_uf();

$response = [
'contact_id' => CRM_Core_Session::getLoggedInContactID(),
'user_id' => $authxUf->getCurrentUserId(),
];

CRM_Utils_JSON::output($response);
}

/**
* Present the outcome of an authx login.
*
* Note that the actual authentication is handled in the authentication layer.
* This method just renders the response page after a successful login.
*/
public static function login() {
self::getId();
}

/**
* Logout of Civi+CMS.
*
* GET /civicrm/authx/logout
* POST /civicrm/authx/logout
*/
public static function logout() {
_authx_uf()->logoutSession();
CRM_Utils_JSON::output([]);
}

}
Loading