Microsoft 365: Requested resource was not found (404 not found)

  • Used Zammad version: 6.2.0-1710502706.2f35239d
  • Used Zammad installation type: package
  • Operating system: Ubuntu 22.04.4
  • Browser + version: Chrome 122.0.6261.129

Expected behavior:

  • after configuring Microsoft 365 CLIENT ID, CLIENT SECRET and TENANT UUID/NAME expected to redirect to microsoft page when pressing “Add account”

Actual behavior:

  • on “Add account” button press, i get 404 not found page (ss1)
    and the log
I, [2024-03-17T22:17:05.126916#32981-141940]  INFO -- : Started GET "/api/v1/external_credentials/microsoft365/link_account" for 192.168.1.15 at 2024-03-17 22:17:05 +0000
I, [2024-03-17T22:17:05.145466#32981-141940]  INFO -- : Processing by ExternalCredentialsController#link_account as HTML
I, [2024-03-17T22:17:05.145755#32981-141940]  INFO -- :   Parameters: {"provider"=>"microsoft365"}
I, [2024-03-17T22:17:05.175303#32981-141940]  INFO -- : Redirected to https://login.microsoftonline.com/[tenant_id]/oauth2/v2.0/authorize?access_type=offline&client_id=[client_id]&prompt=login&redirect_uri=https%3A%2F%2F[zammad_url]%2Fapi%2Fv1%2Fexternal_credentials%2Fmicrosoft365%2Fcallback&response_type=code&scope=https%3A%2F%2Foutlook.office.com%2FIMAP.AccessAsUser.All+https%3A%2F%2Foutlook.office.com%2FSMTP.Send+offline_access+openid+profile+email
I, [2024-03-17T22:17:05.177699#32981-141940]  INFO -- : Completed 302 Found in 32ms (ActiveRecord: 5.7ms | Allocations: 5456)
I, [2024-03-17T22:17:05.411210#32981-143240]  INFO -- : Started GET "/[tenant_id]/oauth2/v2.0/authorize?access_type=offline&client_id=[client_id]&prompt=login&redirect_uri=https%3A%2F%2F[zammad_url]%2Fapi%2Fv1%2Fexternal_credentials%2Fmicrosoft365%2Fcallback&response_type=code&scope=https%3A%2F%2Foutlook.office.com%2FIMAP.AccessAsUser.All+https%3A%2F%2Foutlook.office.com%2FSMTP.Send+offline_access+openid+profile+email" for 192.168.1.15 at 2024-03-17 22:17:05 +0000
I, [2024-03-17T22:17:05.419716#32981-143240]  INFO -- : Processing by ErrorsController#routing as HTML
I, [2024-03-17T22:17:05.419845#32981-143240]  INFO -- :   Parameters: {"access_type"=>"offline", "client_id"=>"[client_id]", "prompt"=>"login", "redirect_uri"=>"https://[zammad_url]/api/v1/external_credentials/microsoft365/callback", "response_type"=>"code", "scope"=>"https://outlook.office.com/IMAP.AccessAsUser.All https://outlook.office.com/SMTP.Send offline_access openid profile email", "a"=>"[tenant_id]/oauth2/v2.0/authorize"}
E, [2024-03-17T22:17:05.432282#32981-143240] ERROR -- : No route matches [GET] /[tenant_id]/oauth2/v2.0/authorize (ActionController::RoutingError)

then i tried to manual browse to the redirected url login.microsoftonline.com… after returning from ms login panel, i got a 500 error with the below log (ss2)

I, [2024-03-17T22:17:51.683218#32981-143360]  INFO -- : Started GET "/api/v1/external_credentials/microsoft365/callback?code=[FILTERED]&session_state=710c713e-c7a9-4e8e-a47a-017a544da5fd" for 192.168.1.15 at 2024-03-17 22:17:51 +0000
I, [2024-03-17T22:17:51.692956#32981-143360]  INFO -- : Processing by ExternalCredentialsController#callback as HTML
I, [2024-03-17T22:17:51.693060#32981-143360]  INFO -- :   Parameters: {"code"=>"[FILTERED]", "session_state"=>"710c713e-c7a9-4e8e-a47a-017a544da5fd", "provider"=>"microsoft365"}
E, [2024-03-17T22:17:52.170439#32981-143360] ERROR -- : unexpected token at '{"aud":"[client_id]","iss":"https://login.microsoftonline.com/[tenant_id]/v2.0","iat":1710713572,"nbf":1710713572,"exp":1710717472,"email":"[email]","name":"Άγγελο��3���s���s�����������
XL�M�L�X�M�MKXML��N
                   �ؘ̍���Y�H��Y�\��Y�\�\��[YH���]�[�[ZX˙܈����
                                                            �V�LU�Ւ�L��XU^Ԝ��ݘ��ؐ�Z��[�֞���Y�PX�ˈ��X����
і��NNY�W��Ҝ�                                                                                          [����]��V�T�
��KNM�KL،LXM\���T������MM��
            MX�Ẍ�]H����ތ[��X��S�U[^TNPPH��\������' (JSON::ParserError)
lib/external_credential/microsoft365.rb:285:in `user_info'
lib/external_credential/microsoft365.rb:51:in `link_account'
app/models/external_credential.rb:21:in `link_account'
app/controllers/external_credentials_controller.rb:43:in `callback'
app/controllers/application_controller/has_download.rb:17:in `block (4 levels) in <module:HasDownload>'
app/controllers/application_controller/has_download.rb:16:in `block (3 levels) in <module:HasDownload>'
app/controllers/application_controller/has_download.rb:15:in `block (2 levels) in <module:HasDownload>'
app/controllers/application_controller/handles_transitions.rb:16:in `handle_transaction'
I, [2024-03-17T22:17:52.172447#32981-143360]  INFO -- : Completed 500 Internal Server Error in 479ms (ActiveRecord: 5.6ms | Allocations: 6823)
F, [2024-03-17T22:17:52.173549#32981-143360] FATAL -- :   
[30dd5e4a-63ba-4e91-a0a3-0697a16cfca7] ArgumentError (invalid byte sequence in UTF-8):
[30dd5e4a-63ba-4e91-a0a3-0697a16cfca7]   
[30dd5e4a-63ba-4e91-a0a3-0697a16cfca7] app/controllers/application_controller/handles_errors.rb:97:in `match?'
[30dd5e4a-63ba-4e91-a0a3-0697a16cfca7] app/controllers/application_controller/handles_errors.rb:97:in `humanize_error'
[30dd5e4a-63ba-4e91-a0a3-0697a16cfca7] app/controllers/application_controller/handles_errors.rb:80:in `block (2 levels) in respond_to_exception'
[30dd5e4a-63ba-4e91-a0a3-0697a16cfca7] app/controllers/application_controller/handles_errors.rb:77:in `respond_to_exception'
[30dd5e4a-63ba-4e91-a0a3-0697a16cfca7] app/controllers/application_controller/handles_errors.rb:35:in `internal_server_error'


Hi @angel. Please check your configuration, it’s working fine for my M365 account.