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.

Issue fork o365-3544571

Command icon 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:

Comments

koenvanmeijeren created an issue. See original summary.

koenvanmeijeren’s picture

Issue summary: View changes
koenvanmeijeren’s picture

Issue summary: View changes

smulvih2 made their first commit to this issue’s fork.

smulvih2 changed the visibility of the branch 3544571-sso-login-does to hidden.

smulvih2 changed the visibility of the branch feature/sso-multilingual-fix to hidden.

smulvih2 changed the visibility of the branch feature/sso-multilingual-fix to active.

smulvih2’s picture

Status: Active » Needs review
StatusFileSize
new2.25 KB

I'm having the same issue on my multilingual site. I have changed the helper function from strStartsWith() to strContains() 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.

fabianderijk’s picture

@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.

fabianderijk’s picture

I've updated the MR so the the newly added unit tests don't fail in this branch.

smulvih2’s picture

Status: Needs review » Reviewed & tested by the community

@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

fabianderijk’s picture

Status: Reviewed & tested by the community » Fixed

Thanks, this is now added to the dev version. I will release a new beta version soon. And hopefully a stable version as well.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.