Comments (9)
@jonnadams I'm not familiar with D7 REST, so I can't tell for sure: are you working with D8?
from angular-drupal.
Looks like he is using D8 there. I think there is now a problem this module alongside Drupal 8.2, I believe the login mechanism has changed: https://www.drupal.org/documentation/modules/rest/javascript#comment-11731955
So I think we need to change this in jDrupal here: https://github.com/easystreet3/jDrupal/blob/8.x-1.x/src/includes/rest.inc.js#L82
Plus, for both D7 and D8, I believe the new X-CSRF-Token
may be included (it for sure is in D7) in the response, so if we use that when it comes back, the subsequent connect call won't need to fetch another token.
from angular-drupal.
I believe your correct signalpoint I am unable to login with D8.2.3. I think it "may" have something to do with: https://www.drupal.org/node/2403307? I am unsure though. I cannot seem to find out what changed in the api.
from angular-drupal.
@webdobe Last week I updated jDrupal to work properly with D8.2.*, so I think if you just download the latest jdrupal.min.js and include it in your index.html file, then angular-drupal should start working again for user login.
from angular-drupal.
Hmm I have the latest... I think it may have something to do with CORS. With the change of adding CORS config to a separate YAML file. I am having a hard time finding out how to make this work correctly....
Ok so While I was typing this I logged some connections. It appears that I need to be sending my requests to drupal using withCredentials set to true. Since jdrupal is using XMLHttpRequest; I am unable to use angular's httpprovider interceptor to change the withCredentials on the request.
$httpProvider.interceptors.push([
function() {
return {
request: function(config) {
config.withCredentials = true;
return config;
}
};
}
]);
Instead I have to be able to do this:
jDrupal.connect = function() {
return new Promise(function(resolve, reject) {
var req = new XMLHttpRequest();
req.withCredentials = true;
Maybe you have an idea?
from angular-drupal.
Well I found the:
/**
* Pre process a rest call.
* @param {XMLHttpRequest} xhr
* @param {*} data
*/
function hook_rest_pre_process(xhr, data) {
// Do stuff before the rest call...
}
So I bet I can do something with that. But where do I use the hook?
from angular-drupal.
Figured it out. I had to add drupal.modules['modulename'] = true;
to my user service and add the
modulename_res_pre_process(xhr) {
xhr.withCredentials = true;
}
Outside the service.
from angular-drupal.
@webdobe Can you go into more detail in how/where you implemented this in your angular app?
from angular-drupal.
@jsheffers So the modulename_res_pre_process(xhr) function I placed in my user service file but outside the service. But you need to add the drupal.modules['modulename'] within your service. This is then added to every rest call stating that your sending withCredentials. The rest of the CORS configuration is done in the services.yml file in drupal 8.x-3.x+
My Cors config looks like this (sites/default/services.yml):
cors.config:
enabled: true
# Specify allowed headers, like 'x-allowed-header'.
allowedHeaders: ['*']
# Specify allowed request methods, specify ['*'] to allow all possible ones.
allowedMethods: ['*']
# Configure requests allowed from specific origins.
allowedOrigins: ['http://localhost:9000'] // or to my live site https://jesselongacre.com you need this otherwise the browser will say the drupal side rejected it.
# Sets the Access-Control-Expose-Headers header.
exposedHeaders: false
# Sets the Access-Control-Max-Age header.
maxAge: false
# Sets the Access-Control-Allow-Credentials header. // this is where the withCredentials is supported
supportsCredentials: true
Make sure to clear your cache after making the cors changes as drupal 8 I believe caches all this.
Additionally, you may need to setup # cookie_domain: '.example.com' in your services.yml file this will make sure that your cookies are passed to the app. Hense the withCredentials bit.
from angular-drupal.
Related Issues (20)
- Merge with jDrupal? HOT 5
- user/login.json 404 (Not Found) with drupal.user_login HOT 8
- Rebuild angular-drupal.min.js
- Update README examples
- Create dev branch HOT 2
- 403 Forbidden on saving a user (PATCH) HOT 7
- CSRF token issue for Safari/ios HOT 1
- bower.js needs to know where the src file is HOT 2
- Cookie domain HOT 3
- Login issue with different token and sessid HOT 7
- How to get success message HOT 6
- How to create node with entity field HOT 15
- Loading other entities HOT 3
- drupal.userLogout doesn't succeed. HOT 9
- How to upload images to image field? 7.x HOT 5
- Login response is correct, but printing out the user id still shows anonymous HOT 3
- 403 PUT/PATCH on user register/update on a multilingual site HOT 6
- drupal node_save created time HOT 3
- ios incompatibilities HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular-drupal.