Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any support for subdomain authentication with drupal 7? #50

Open
ghost opened this issue Oct 27, 2016 · 5 comments
Open

Any support for subdomain authentication with drupal 7? #50

ghost opened this issue Oct 27, 2016 · 5 comments

Comments

@ghost
Copy link

ghost commented Oct 27, 2016

When i collect node data from example.com site, its collect data into sub.example.com. but, when i trying to get current user information, its not working, its return anonymous.

How can i solve authentication with jdrupal, any suggestion?

@signalpoint
Copy link
Owner

@tazimhossain I don't know. I hear there is a "cookie domain" setting that can go in settings.php to allow the cookie to be placed on another domain, I've never tried it though, so I'm not entirely certain on its capabilities.

@ghost
Copy link
Author

ghost commented Oct 29, 2016

Thanx for reply. I am already doing that, but dont know why its not working for authentication. :(

@adam-clarey
Copy link
Contributor

adam-clarey commented Mar 5, 2017

I've had this problem trying to run various requests from an app on a sub-domain.

After a lot of debugging I've managed to get it working but it requires the 'withCredentials' flag adding to the request.

I've attached a patch with adds a new setting to the jDrupal object, its a non-breaking change so it can be merged without affecting any existing installations.

To use this functionality you just need to set the config:

jDrupal.config('withCredentials', true);

On the server side, I have the following headers set:

header("Access-Control-Allow-Origin: [subdomain]");
header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS");
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Allow-Headers: Content-Type');
withCredentials.patch.zip

@signalpoint
Copy link
Owner

Thank you @adam-clarey , any chance you'd like to turn this into a Pull Request?

@adam-clarey
Copy link
Contributor

adam-clarey commented Mar 8, 2017

Ive since realised its not necessary, you can just use the hook_rest_pre_process:

// When initialising your app
function init() {
  jDrupal.modules['cordova'] = ['cordova_rest_pre_process', 'cordova_rest_post_process'];
}

/**
 * Implements hook_rest_pre_process()
 * @param xhr
 * @param data
 */
window.cordova_rest_pre_process = function(xhr, data) {

  // Required for sharing cookies across domains.
  xhr.withCredentials = true;

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants