3

I have overridden Drupal's login process by calling a REST API which returns a 'true' or a 'false' depending on whether the login was successful or not. Once successful, I'm logging the user in by using a particular Drupal user account.

Would it be possible to change Drupal's Session ID to the one specified by the REST API call? Currently the REST API Call is giving me a JSESSIONID cookie and I was wondering if its possible to map this cookie to the one Drupal generates when the user logs in. Reason I need this is because I need keep track of this JSESSIONID to call other API methods related to the logged in user.

1 Answer 1

0

You cant save off the JSESSIONID into the user attributes, eg data column, in D6 or D7. You simply do this in your code with:

$_SESSION['JSESSIONID'] = /* some value here */;

or wherever you call user_save() in your custom login you can pass $edit['data'] = array('jsessionid' => 12341234); from the user_save documentation:

$edit: An array of fields and values to save. For example array('name' => 'My name'). Key / value pairs added to the $edit['data'] will be serialized and saved in the {users.data} column.

it then becomes accessible from a fully loaded $user object as simply a field of the user ... $jsessionid = $user->jsessionid; and you can use it as needed.

1
  • \Drupal::service('session')->setId($jsessionid); Should also work. \Drupal::service('session')->getId(); to get the id.
    – DiDebru
    Jun 8, 2018 at 6:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.