Problem/Motivation
I have a multilingual website. When I install and configure the o365 module and try to log in via Microsoft SSO login, it does not work. I then receive this message in the logs: "An anonymous user tried to log in using o365, this is not allowed."
Steps to reproduce
1. Configure your site as multilingual, e.g. www.example.com/nl, www.example.com/en
2. Install and configure the o365 module
3. Go to the login form, e.g. www.example.com/nl/user/login
4. Click on the "login with Microsoft" link
This results in a redirect back to the login form and a message in the logs "An anonymous user tried to log in using o365, this is not allowed.".
Drupal version: 11.2.3
PHP version: 8.4.8
Proposed resolution
Update the AuthenticationService::redirectToAuthorizationUrl to correctly handle requests from urls with a language code.
If I update the code on the first line of the redirectToAuthorizationUrl method from
if ($this->currentUser->isAnonymous() && !$this->helperService->strStartsWith($this->request->getPathInfo(), '/o365/login')) {
to
if ($this->currentUser->isAnonymous() && !$this->helperService->strStartsWith($this->request->getPathInfo(), '/nl/o365/login')) {
it works correctly again.
Of course, the solution needs to be more dynamic, but I wanted to show the possible solution.
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | o365_sso-fix-multilingual-login-3544571-8.patch | 2.25 KB | smulvih2 |
Issue fork o365-3544571
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- feature/sso-multilingual-fix
changes, plain diff MR !44
- 3544571-sso-login-does
compare
Comments
Comment #2
koenvanmeijeren commentedComment #3
koenvanmeijeren commentedComment #9
smulvih2I'm having the same issue on my multilingual site. I have changed the helper function from
strStartsWith()tostrContains()to account for the language prefix in the URL path. I have also included a patch to use in my project now. I will test this in our Azure environment in the next few days and report back.Comment #10
fabianderijk@smulvih2 have you tested this on your environment? I will setup a multilingual site this weekend and test it out myself. I looks good for now, but lets be sure.
Comment #11
fabianderijkI've updated the MR so the the newly added unit tests don't fail in this branch.
Comment #12
smulvih2@fabianderijk I am using my patch in #9 and it has been working for me using multilingual with path prefix (/en, /fr). Changes in MR look good to me! RTBC
Comment #13
fabianderijkThanks, this is now added to the dev version. I will release a new beta version soon. And hopefully a stable version as well.