2

i am trying to get authenticated data after login with services module. ive a drupal services set up at openshift and the htmls are in my devices.

i managed to login, get authenticated, get the session name, id, token etc. but when i tried to fetch data for authenticated users, im getting the "403: Access denied for user anonymous" error. same on both firefox and chrome.

ive used postman in chrome and poster in firefox. im getting all the desired results. if i logged in drupal and open the url directly, im getting the right results too. that proves my services and everything are correctly configured.

i also tried examples with curl and php from my localhost, and they worked fine without any problem.

ive searched for solutions here and drupal forum. i did saw a few almost similar problems to mine in here, but they were not answered (like this one Post AJAX JSON with session id). after 5 days of failure, i think i should create a new post.

below are the codes. i hoped someone could get me to the right direction. thanks in advance.

$.post( "https://drupal-halmsx.rhcloud.com/services/auth/user/login.json", 
    { "username": username, "password": password })
  .done(function(data) {
        console.log(data);

        var sessid = data.sessid;
        var session_name = data.session_name;
        var user = data.user;
        var token = data.token;

        $.cookie(session_name, sessid, {path: '/'}); // set session name and id
        //$.cookie("token", token);

        console.log($.cookie());
        console.log(user.uid);

        $.ajax({
            type: "GET",
            url: "https://drupal-halmsx.rhcloud.com/services/auth/user/10.json", // hardcode this for example.
            beforeSend: function(xhr) {
                xhr.setRequestHeader('X-CSRF-Token', token)
            },
            dataType: "json"
        });     
    })
    .fail(function (data) {
        console.log(data);
    });
  • been researching since i last post this and found that none of the similar question in all forums i went to are answered. decided to create hybrid app with drupalgap to manage the login session. but still hoping this would be answered one day. – user3814537 Jan 31 '15 at 14:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.