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

/Drupal/user/login returns a 'page not found' error #81

Open
Maplestrip opened this issue Jan 10, 2018 · 11 comments
Open

/Drupal/user/login returns a 'page not found' error #81

Maplestrip opened this issue Jan 10, 2018 · 11 comments

Comments

@Maplestrip
Copy link

Hello, I am trying to connect a Drupal and Moodle website I have on my Apache server, accessing it through localhost. However, I am running into two main issues. My Moodle website is named "CELO", and my Drupal website is named "drupal-7.x-dev" in this situation.

My Drupal website cannot go to "/drupal-7.x-dev/?q=user/login?moodle_url=true&destination=CELO" (or "/drupal-7.x-dev/user/login?moodle_url=true&destination=CELO"). It gives the following error:

Page not found
The requested page "/drupal-7.x-dev/?q=user/login?moodle_url=true&destination=CELO" could not be found.

An alternative path I've tried is "user/login?moodle_destination=CELO", but this gives the same error.

Furthermore, mapping Drupal fields in Moodle is not possible. All of the fields can only be changed to '0'.
image
Do note that the mapping '0' is only available to me when I use the correct ip adresses for cookies, suggesting to me that a connection is being made, but that Drupal is not handling it correctly. However, I have installed all needed Drupal modules and more, and created the neccessary mappings.

Does anyone have any idea what could be going wrong here?

@netw3rker
Copy link
Collaborator

If you can't reach http://localhost/drupal-7.x-dev?q=user/login this isn't an sso problem. you should double check your drupal site configuration.

One thing you might want to ensure is that you have mod_rewrite installed (if you are using apache) or have url rewriting enabled if you are using IIS.
The reason for this is, I'm not 100% sure that the system is configured to work without "clean urls" enabled on drupal. and if your urls are using the ?q= format, then you don't have it enabled.

Give that a shot & lemme know what happens.

@Maplestrip
Copy link
Author

Thank you for your response!

I now correctly installed mod_rewrite and am using clean urls. I don't know how much closer this brings me to the solution I need. When I go to localhost/drupal-7.x-dev/user/login?moodle_url=true&destination=CELO, I can now find a login page. Logging in just brings me to localhost/drupal-7.x-dev/CELO, however, which does not exist.

I feel like I missed something really obvious when configuring the Drupal side of things, but I don't know what it is. The Moodle SSO module is enabled, the moodle-drupalservices module is enabled on my Moodle site. The domains are "localhost/drupal-7.x-dev" and "localhost/CELO".

Any idea what could still be wrong?

@netw3rker
Copy link
Collaborator

good, you are getting closer. the destination is definitely not correct. at a minimum it should be destination=/CELO I'm pretty sure that is a problem w/in the moodle configuration. try changing the base url in the moodle settings to either have the / or have the full url

@Maplestrip
Copy link
Author

Maplestrip commented Jan 12, 2018

I just changed the code in auth.php to include such a slash, like this:
redirect($this->config->host_uri . "user/login?moodle_url=true&destination=/" . $path . $args);
Sadly, this doesn't seem to have much of an effect. I just forced login again, so going to localhost/CELO automatically redirects to http://localhost/drupal-7.x-dev/CELO/, which just gives me a "page not found".

I don't know if this is relevant, but in my Moodle's config.PHP I currently have:
$CFG->wwwroot = 'http://127.0.0.1/CELO'; ... $CFG->forced_plugin_settings['auth_drupalservices']['cookiedomain']='localhost';

(I have also tried changing these to my local IP adress, rather than localhost or 127.0.0.1)

@netw3rker
Copy link
Collaborator

You'll definitely want to make some changes here. The domain you access must be the same (or a subdomain of) the cookie domain. eg the $CFG->wwwroot value should be http://localhost/CELO and the cookie domain should be localhost. Then, you must access both moodle and drupal using the http://localhost/ domain.

If you set that up in moodle. Go over to drupal and log in as user 1 (the root user). once you've done that you should then be able to switch back to moodle, log in, and configure the sso plugin.

One thing you can check to confirm things are working is, add the "editThisCookie" plugin to chrome. then once you've logged in to drupal, use that tool to check to see what the drupal session cookie looks like. it should read: localhost "SESS12345ABCDEFG". next, switch over to moodle, and check for that same cookie. If you don't see it, there's a problem with Drupal's cookie assignment (if this is the case, it's because you have drupal creating a cookie that is specific to localhost/drupal and you'll need to fix that in settings.php). Next, log in to moodle and use editThisCookie to check for the moodle session (it will look similar). If it exists, switch over to drupal and confirm you still see it (based on your configs, you should, but if you don't it's the same problem as above).

Do some debugging there and let me know what comes up. the /CELO might be a wild goose chase, so lets see what happens with this.

@Maplestrip
Copy link
Author

I have changed everything to say 'localhost', as you described, and just installed EditThisCookie. The Drupal session cookie correctly appears on Moodle, but the Moodle cookie does not appear on Drupal. I just added the following code to fix that issue:
$CFG->sessioncookiepath = 'http://localhost';

I am not exactly sure what is happening right now: I can no longer login to Moodle. When I click the "login" link/navigate to /login/index.php, I am solely informed that "Class 'object' not found". Googling the error, I found that it was brought up a few months ago in a similar situation: https://moodle.org/mod/forum/discuss.php?d=361828
Changing "stdclass()" to "object()" as described in that thread did not improve matters much, as I am now told that there is an error writing to the database.

Any idea what to do next? I feel like I am making progress, so thanks a lot for the help thus far!

@netw3rker
Copy link
Collaborator

Based on this: https://github.com/moodle/moodle/blob/master/lib/sessionlib.php#L137 I suspect that your $CFG->sessioncookiepath is incorrect, and needs to simply be /. that's likely why you aren't able to log in. (if the browser gets a malformed cookie, it throws it out. so your session is likely being destroyed the instant it is created).

you'll note that there are 2 variables used to construct the session cookie: $CFG->sessioncookiedomain and $CFG->sessioncookiepath make sure that $CFG->sessioncookiedomain is .localhost and the $CFG->sessioncookiepath = '/'.

@Maplestrip
Copy link
Author

Doing that, and changing instances of 'localhost' to '.localhost', brings me a step forward once again. I am now redirected to the Drupal "Page not found" page, The text is

The requested page "/drupal-7.x-dev/CELO/" could not be found.

Interestingly, it no longer seems to use the redirect code from auth.php.

@Maplestrip
Copy link
Author

I know that this discussion has died down (in part because I was sick two weeks ago and didn't go to work for a few days), but I would be forever thankful if the problem I'm left with could be solved. I think it's probably a Drupal-side issue, but I have no idea how to fix this connection.

@netw3rker
Copy link
Collaborator

I'm almost 100% sure this is a drupal problem too. I'm working on continuous integration tests for this, and one of the tests is the structure of your environment. I should have that this weekend. Once I do, I'll have a much better answer for you.

In the meantime, take a look at the redirect in the moodle_sso module. My guess is, it's using the domain/drupal-7 path as the base URL to redirect to. If you check the docs and make it an absolute URL, that might help.

More to come.

@Maplestrip
Copy link
Author

Looking through htdocs\drupal-7.x-dev\sites\all\modules\moodle_sso, I find no mention of CELO at all. There are no options to configure Moodle_SSO on the Drupal website either. Where am I supposed to find the path for the base URL to redirect to?

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

No branches or pull requests

2 participants