-
-
Notifications
You must be signed in to change notification settings - Fork 825
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
Add authx_login()
API for backend script authentication
#22239
Conversation
Before: If the authenticator encounters an error, it sends a response document. After: The authenticator encoutners an error, it may either: - (Default) Send a response document - (Option) Emit an exception
(Standard links)
|
This seems ok just some questions:
|
As mentioned in civicrm#22239 (comment), there can be an exception: ``` Error: Call to a member function id() on bool in ...\CRM\Utils\System\Drupal8.php on line 359 #0 ...\ext\authx\Civi\Authx\Authenticator.php(380) ``` The function signature specifies `@return int|null`. Various callers appear to expect this, and that seems to be how it behaves on D7/WP.
@demeritcowboy Thanks. I've extended the tests to cover a few of the error scenarios - and added some more checks/exceptions along the way. So far, on local D7 and WP, it throws the asserted |
Thanks. I didn't check the drupal function but yes it seems the right place to fix that. A couple things still though: (A)
but
(B) |
Missed this in my previous reply. This flag decides whether the authenticated identity is stored in a persistent/cookie-based session -- alternative names might be For my current target use-case (with background/system/worker process running through pipe), it should not store a session/cookie. However, based on experience with other auth APIs, I expect that some folks would look at It seemed important to me that the developer calling
Authx has been treating this as a policy issue rather than a hardcoded issue. A couple relevant links:
This all sort of raises the question - if someone calls The target use-case right now (backend-y/system-y tasks) does not match any of the flows in https://docs.civicrm.org/dev/en/latest/framework/authx/#flows. I thought about adding a new flow and didn't... but the way it looks now, it probably should a distinct flow. TLDR: I should probably rework this way that:
OK, I haven't looked at that yet - will try it today. |
As mentioned in civicrm#22239 (comment), there can be an exception: ``` Error: Call to a member function id() on bool in ...\CRM\Utils\System\Drupal8.php on line 359 #0 ...\ext\authx\Civi\Authx\Authenticator.php(380) ``` The function signature specifies `@return int|null`. Various callers appear to expect this, and that seems to be how it behaves on D7/WP.
Replaced by #22292. The signature is slightly different. The By setting |
Overview
Adds a function to login as a user. It is cross-platform; accepts contact ID, user ID, or username; and it updates relevant services (eg Civi session; Drupal
$user
; MySQL@civicrm_user_id
).(This is a dependency for https://lab.civicrm.org/dev/core/-/issues/1304. ping @seamuslee001)
Before
Not available
After
This shares much of its implementation with the login processes used by authx for JWT+ApiKey+Password authentication.
Like the JWT/key/password implementations, this has cross-platform E2E testing.
Technical Details
The use-case is like this: you have some background worker processes. These processes need to execute some tasks on behalf of a user. This is similar to
authx
's existing login functionality in some ways (eg you want it to be portable; to integrate with login/session mechanics in the CMS; and to work with a range of user-accounts); but it also differs in an important way (eg there is no authentication credential presented by a user; the decision is made by a background agent).The
authx_login()
method basically uses the same login mechanics as the rest ofauthx
, but it doesn't require specific credentials.A quick way to see it in action is with
cv
,drush
, orwp-cli
. In each of these commands,There are some existing alternatives, but each has issues.
CRM_Utils_System::loadBootStrap(...)
and pass username/password. However, in this function, the authentication and bootstrap processes are tightly coupled -- and some of its expectations are wonky.\Drupal::service('account_switcher')->switchTo(...)
orwp_set_current_user()
. Obviously not portable.cv --user
,drush --user
, orwp --user
. However, these require you pick the target principal/user before launching the script.CRM_Core_Config::singleton()->userSystem->loadUser(...)
. However, this only workswith a username (not contactId/userId); the incantation is very internal; and test coverage is unclear.