UPDATE:
I've tried implementing W.M.'s solution below, however upon attempting to enable the module, I get the white screen of death. Nothing shows up in the logs for the error.
For my custom module, I have two files:
ra_login.module
ra_login.info
Info file:
name = RA Login
description = Check ID and Login if there is a match, else go to Registration Page.
core = 7.x
; Information added by Drupal.org packaging script on 2013-12-16
version = "7.x-1.0"
core = "7.x"
project = "ra_login"
datestamp = "1387203506"
Module File:
<?php
function ra_login_menu()
{
$items['authenticate-by'] = array( // or any other custom path you choose
'title' => 'Login by SSO',
'access callback' => true, // no point in authenticating at this point in code execution
'page callback' => 'ra_login_function',
'type' => MENU_CALLBACK,
);
return $items;
}
function ra_login_function($CONTACTID)
{
// post the data to /authenticate-by as json with a parameter / property named CONTACTID holding the CONTACTID
$postData = file_get_contents('php://input');
$Data = json_decode($postData);
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'user')
->propertyCondition('uid', 1, '<>')
// User number 1 should not be able to log in using this method
->fieldCondition('field_contactid', 'value', $Data->CONTACTID, '=')
->range(0,1);
$result = $query->execute();
if (isset($result['user'])) {
$uid = array_keys($result['user'])[0];
$account = user_load($uid);
global $user;
$user->uid = $uid;
$user->name = $account->name;
$user->timezone = $account->timezone;
user_login_finalize(); // Log user in
drupal_goto('/user'); // or any other path to redirect logged in users to
} else {
drupal_goto('/user/register');
}
}
Again, for some reason when I try to enable the module, I get a white screen.
Thanks for anyone who can help!