tareko / Kitab-Al-Shifa

Kitab Al Shifa is an electronic shift scheduling and trading program designed primarily with an Emergency Department in mind for physician scheduling.
9 stars 4 forks source link

Authenticate against Drupal API #115

Closed tareko closed 4 years ago

tareko commented 8 years ago

Authenticate the user against Drupal API instead of the joomla DB

tareko commented 8 years ago

This is quite undocumented, but it might work:

https://github.com/CakeDC/OAuth2

tareko commented 8 years ago

Ignoring above re: OAuth2, it seems that won't work as well as just using the drupal API for login.

https://api.drupal.org/api/drupal/modules!user!user.module/function/user_authenticate/7.x

Sample code:

function user_authenticate($name, $password) {
  $uid = FALSE;
  if (!empty($name) && !empty($password)) {
    $account = user_load_by_name($name);
    if ($account) {
      // Allow alternate password hashing schemes.
      require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');
      if (user_check_password($password, $account)) {
        // Successful authentication.
        $uid = $account->uid;

        // Update user to new password scheme if needed.
        if (user_needs_new_hash($account)) {
          user_save($account, array('pass' => $password));
        }
      }
    }
  }
  return $uid;
}

How to bootstrap Drupal (probably overkill, but not a bad start to test / dev):

https://api.drupal.org/api/drupal/includes!bootstrap.inc/function/drupal_bootstrap/7.x

  define('DRUPAL_ROOT', '/path/to/drupal');
  require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
  $variables['url'] = 'http://example.com'; 
  drupal_override_server_variables($variables);
  drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
tareko commented 4 years ago

Wontfix. Moved to LDAP