RESTful-Drupal / restful

RESTful best practices for Drupal
https://drupal.org/project/restful
419 stars 173 forks source link

Angular form example 403 #461

Open t14 opened 9 years ago

t14 commented 9 years ago

Hi I am using this example, https://github.com/Gizra/angular-drupal-forms-example with the restful module. I am trying to use an Angular form outside of a drupal installation to create content from the article content type.

I am able to login but I am not able post a new article. I am getting a 403 with the message "you do not have access to create a new articles resource"

Also is there a full CRUD example that uses angular (outside a drupal installation) and the restful module? I noticed the angular example module is done inside a drupal installation.

Thanks for your time

edhollinghurst commented 9 years ago

The way I do this is to save the access token to the $rootScope and then pass this into the headers of the post request. So you do something like this:

var URL = API_URL + '/v1.0/articles',
    data = {
      'title': 'Node title',
      'body': 'Body'
    },
    config = {
      headers:  {
        'access_token': $rootScope.globals.currentUser.accessToken
      }
    };

$http.post(URL, data, config);
t14 commented 9 years ago

Looks like tis is what is happening in the code example that I am using (see link below), but it does not allow access to create an article post

https://github.com/Gizra/angular-drupal-forms-example/blob/master/app/scripts/services/articlesresource.js

jmdall commented 9 years ago

You can look at generator-hedley. It handle authentification with drupal by injecting access_token to every $http here. There's only the R of CRUD in my memory but maybe it will help you a bit. Creating content is not really that different.

t14 commented 9 years ago

Ok thanks, looks like the angular-drupal-form example is a little out dated. The access token object was empty this is why I was not able to to create an article. I also noticed that the logic on line 622 here https://github.com/RESTful-Drupal/restful/blob/dbff4999a1706f6324771a44956edad9f10a249e/plugins/restful/RestfulEntityBase.php

does not actually work. I was only able to create an article by giving the anonymous user role permission to create an article.

e0ipso commented 9 years ago

It would be greatly appreciated if you could update the angular example to reflect the latest version in the RESTful module. On Apr 9, 2015 10:49, "t14" notifications@github.com wrote:

Ok thanks, looks like the angular-drupal-form example is a little out dated. The access token object was empty this is why I was not able to to create an article. I also noticed that the logic on line 622 here https://github.com/RESTful-Drupal/restful/blob/dbff4999a1706f6324771a44956edad9f10a249e/plugins/restful/RestfulEntityBase.php

does not actually work. I was only able to create an article by giving the anonymous user role permission to create an article.

— Reply to this email directly or view it on GitHub https://github.com/RESTful-Drupal/restful/issues/461#issuecomment-91155212 .

t14 commented 9 years ago

will open a pull request soon