function _services_keyauth_alter_methods in Services 7
Same name and namespace in other branches
- 6.2 auth/services_keyauth/services_keyauth.inc \_services_keyauth_alter_methods()
1 string reference to '_services_keyauth_alter_methods'
- services_keyauth_authentication_info in auth/
services_keyauth/ services_keyauth.module - Implements hook_authentication_info().
File
- auth/
services_keyauth/ services_keyauth.inc, line 47 - The implementation of the key authentication scheme
Code
function _services_keyauth_alter_methods(&$methods) {
// Skip this if no services have been activated
if (!is_array($methods) || empty($methods)) {
return;
}
// sessid arg
$arg_sessid = array(
'#name' => 'sessid',
'#type' => 'string',
'#description' => t('A valid sessid.'),
);
$arg_domain_time_stamp = array(
'#name' => 'domain_time_stamp',
'#type' => 'string',
'#description' => t('Time stamp used to hash key.'),
);
$arg_nonce = array(
'#name' => 'nonce',
'#type' => 'string',
'#description' => t('One time use nonce also used hash key.'),
);
// domain arg
$arg_domain_name = array(
'#name' => 'domain_name',
'#type' => 'string',
'#description' => t('A valid domain for the API key.'),
);
// api_key arg
$arg_api_key = array(
'#name' => 'hash',
'#type' => 'string',
'#description' => t('A valid API key.'),
);
foreach ($methods as $key => &$method) {
// set method defaults
switch ($method['#method']) {
case 'system.connect':
$method['#key'] = FALSE;
$method['#auth'] = FALSE;
break;
default:
$method['#key'] = TRUE;
$method['#auth'] = TRUE;
}
if ($method['#auth'] && variable_get('services_use_sessid', TRUE)) {
array_unshift($method['#args'], $arg_sessid);
}
if ($method['#key'] && variable_get('services_use_key', TRUE)) {
array_unshift($method['#args'], $arg_nonce);
array_unshift($method['#args'], $arg_domain_time_stamp);
array_unshift($method['#args'], $arg_domain_name);
array_unshift($method['#args'], $arg_api_key);
}
}
}