Closed (fixed)
Project:
Services
Version:
7.x-3.5
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
1 Nov 2013 at 17:10 UTC
Updated:
10 Dec 2015 at 16:12 UTC
Jump to comment: Most recent
Why does Services 3.5 set the user to anonymous before doing an access check even though the Cookie and X-CSRF-Token headers are set?
After digging through the code, I see that Services perform the following steps:
services_controller_execute() -> _services_controller_execute_preserve_user_switch_anonymous() -> _services_controller_execute_internals() -> _services_sessions_authenticate_call() -> _services_run_access_callback() -> user_access() -> FAILED!
We get the failure because the anonymous user is not allow to get a system variable.
I would appreciate some help with this (: Thanks!
Comments
Comment #1
bfuzze9898 commentedI'm having the same problem. Did you figure this out?
Comment #2
monaw commentedUnfortunately after spending many weeks and not finding a solution, I downgrade my Services back to 3.3 and the problem went away.
If you find a solution, please post back!
Comment #3
ershov.andrey commentedDid you check "Session authentication" on Authentication section on Edit endpoint page?
I had the same issue until I turned on Session authentication checkbox.
Comment #4
ygerasimov commentedUser should get authenticated during _services_sessions_authenticate_call(). If your session cookie is present and session authentication is enabled your user should be authenticated. Please check the settings and let me know.
Comment #6
Anonymous (not verified) commentedi check
1. "Session authentication" on Authentication section and
2. also pass cookie sessionname=sessionid
[SESS7331d9b025b1ad8e51076b5a2cdcf] => HXPzaRimife-CdCh9ZtKWHM-QBt-SttgdV8W_uXw
3. and i am using the services 7.x-3.7 version ...
should i need to downgrade to 7.x-3.3 ? or something else need to do. Please help i working on atleast 10 days..
Thanks
Hi guys ..
I got the solution of this issue its actually
i have to site https://www.test.mysite.com and https://www.mysite.com
i set url as http://test.mysite.com it redirect to www.mysite.com ...so my session id and session name that i got from test server and pass it original server which is wrong ...so am happy above code is correct needy one can use it.
also there is no need to downgrade the services module i use latest version and its working fine....
or there is other method
you can do some changes in services.runtime.inc file
and set in header
as
Authentication="sesionname=sessionid"
if (call_user_func_array($controller['access callback'], $access_arguments) != TRUE) {
global $user;
//added by ranjeet gholave
drupal_add_http_header('Access-Control-Allow-Headers', 'Authentication');
if (isset($_SERVER['HTTP_AUTHENTICATION'])) {
list($session_name, $sessid) = explode('=', $_SERVER['HTTP_AUTHENTICATION']);
session_name($session_name);
$_COOKIE[session_name()] = $sessid;
_drupal_session_read($sessid);
}
else
{
return services_error(t('Access denied for user @user', array(
'@user' => isset($user->name) ? $user->name : 'anonymous',
)), 403);
}
}
Comment #7
Anonymous (not verified) commentedHi guys,
i got this errors "access denied for use ranjeet" when i run url in browser.
www.mysite.com/my_endpoint/blog/retrieve
below is code for reference of services module services.runtime.inc
function _services_run_access_callback($controller, $args) {
// Construct access arguments array.
if (isset($controller['access arguments'])) {
$access_arguments = $controller['access arguments'];
if (isset($controller['access arguments append']) && $controller['access arguments append']) {
$access_arguments[] = $args;
}
}
else {
// Just use the arguments array if no access arguments have been specified
$access_arguments = $args;
}
// Load the proper file for the access callback.
if (!empty($controller['access callback file']) && $access_cb_file = $controller['access callback file']) {
$access_cb_file_name = isset($access_cb_file['name']) ? $access_cb_file['name'] : NULL;
module_load_include($access_cb_file['type'], $access_cb_file['module'], $access_cb_file_name);
}
// Call default or custom access callback.
if (call_user_func_array($controller['access callback'], $access_arguments) != TRUE) {
global $user;
return services_error(t('Access denied for user @user', array(
'@user' => isset($user->name) ? $user->name : 'anonymous',
)), 403);
}
}
Please help me ...
Thanks
Ranjeet gholave
Comment #8
Anonymous (not verified) commentedHi guys ,
access denied for use ranjeet solved i made mistake and enable old custom module because of that same function is called for two times ..one of present in newmycustom and oldmycustom folder so please note that...
same function called 2 times which is different locations.
thanks
Comment #9
Madhuri A commentedAfter adding above code, it gives same error ["Access denied for user anonymous"]
Comment #10
aryashreep commentedHi Guys,
This fix works fine for me https://www.drupal.org/node/1438988 (if you are using uuid).
Thank you.