1

I'm developing a website with an external user authentication provider. The whole login process is external, that I don't need to worry about. Once a user is logged in, the external provider adds extra data in the request headers (i.e. customer id), that I can use to map an external customer id with a user from the Drupal users table.

Which hook suits the best to open a session and login the user programmatically on each page request? (hook_boot() ?)

1 Answer 1

2

As the hook_init() doesn't works for the cached pages so the alternate option that seems to me is the hook_boot() (This hook is run at the beginning of the page request. It is typically used to set up global parameters that are needed later in the request),

However the discussion here on using the session during hook_boot make me feel that hook_boot() is invoked too early to use the session, as Drupal has not yet initialised the session.

There is a trick to avoid the page is cached: Call drupal_page_is_cacheable(FALSE) in hook_init().

Check more here: using drupal sessions during hook_boot

2
  • Wouldn't that be a bad idea to disable page cache globally on the whole site? What about checking in hook_boot() if headers data are available, if yes, set a global variable and disable page cache so that hook_init() is called, which handles the login process. Oct 23, 2013 at 7:30
  • @MikeVranckx Yeah I agree that would be a more accurate way, so you can use a combination of both to server your purpose Oct 23, 2013 at 7:39

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.