function _services_keyauth_alter_methods in Services 6.2
Same name and namespace in other branches
- 7 auth/services_keyauth/services_keyauth.inc \_services_keyauth_alter_methods()
Alter method signatures to add required arguments for key authentication.
Parameters
$methods: An array of all enabled service methods.
1 string reference to '_services_keyauth_alter_methods'
- services_keyauth_authentication_info in auth/
services_keyauth/ services_keyauth.module - Implementation of hook_authentication_info().
File
- auth/
services_keyauth/ services_keyauth.inc, line 60 - 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.'),
'source' => array(
'param' => 'sessid',
),
);
$arg_domain_time_stamp = array(
'name' => 'domain_time_stamp',
'type' => 'string',
'description' => t('Time stamp used to hash key.'),
'source' => array(
'param' => 'domain_time_stamp',
),
);
$arg_nonce = array(
'name' => 'nonce',
'type' => 'string',
'description' => t('One-time-use nonce also used to hash key.'),
'source' => array(
'param' => 'nonce',
),
);
// domain arg
$arg_domain_name = array(
'name' => 'domain_name',
'type' => 'string',
'description' => t('A valid domain for the API key.'),
'source' => array(
'param' => 'domain_name',
),
);
// api_key arg
$arg_api_key = array(
'name' => 'hash',
'type' => 'string',
'description' => t('An SHA-256 hash of the timestamp, domain, nonce, and method name delimited by semicolons and using the remote API key as the shared key.'),
'source' => array(
'param' => 'hash',
),
);
foreach ($methods as $key => &$method) {
// set method defaults
switch ($method['method']) {
case 'system.connect':
$method['key'] = FALSE;
$method['auth'] = FALSE;
break;
default:
if (!isset($method['key'])) {
$method['key'] = TRUE;
}
if (!isset($method['auth'])) {
$method['auth'] = TRUE;
}
break;
}
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);
}
}
}