Escrito por

Pergunta Claudio Vieira · Fev. 3, 2023

Autenticação OAuth 2.0 Microsoft Office 365

Boa tarde,

Utilizo o Caché COS e estou com dificuldade para fazer um POP3 no servidor de e-mail da Microsoft, utilizando a autenticação OAuth 2.0.

Estou utilizando o seguinte programa para realizar essa tarefa:

QGPOP ; Recebe e-mail da Microsoft Office 365
  Set server=##class(%Net.POP3).%New()
  Set server.port=995
  Set server.StoreAttachToFile=1
  Set server.AttachDir="D:\HOME\CNTIRET"
  Set servername="outlook.office365.com"
  Set user="importacao@ferrolene.com.br",pass="xxxxxx"
  Set AccessToken="exxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
  set server.SSLConfiguration="Transnovag"
  Set status=server.Connect(servername,user,pass,AccessToken)
  Do $System.Status.DisplayError(status)
  set status=server.GetMailBoxStatus(.NumMensagens,.TamTotalMensagens)
  !!,"Nr. de mensagens na pasta: ",NumMensagens,!!
  Do $System.Status.DisplayError(status)
  closeserver=server.%Close()
  Quit

 

Estou recebendo a seguinte mensagem de erro:

%SYS>ZR  D ^QGPOP
Erro #6015: Servidor POP3 reportou erro: -ERR Authentication failure: unknown user name or bad password..

 

Será que alguém já conseguiu realizar essa conexão ?

Grato.

Claudio Vieira

Versão do produto: IRIS 2022.1
$ZV: IRIS for Windows (x86-64) 2022.1.1 (Build 374U) Tue Oct 18 2022 17:39:18 EDT

Comments

DC AI Bot · Maio 25 Bot

Yes, this connection has been achieved, but the returned documents point to a few specific requirements in your code and in Microsoft 365 configuration:

  1. If you are using an OAuth access token, do not send the password together with it. The guidance in the retrieved discussion is explicit: when using an access token, the password should not also be sent. [1][2]

  2. For your call syntax, the example correction shown is:

Set status=server.Connect(servername,user,,AccessToken)

and not:

Set status=server.Connect(servername,user,AccessToken)

The empty third parameter is required so that the token is passed as the 4th argument. [1][2]

  1. The token must include the proper mail scopes. The retrieved material specifically mentions using scopes such as:
  • https://outlook.office.com/POP.AccessAsUser.All
  • https://outlook.office.com/SMTP.Send

It also notes that adding additional scopes may prevent the token from working for mail retrieval. [1][2]

  1. Microsoft also requires a tenant ID in the authorization request. The example in the retrieved material uses common for outlook.com accounts, but for your domain you may need to use your tenant ID instead of common. [1][2]

  2. One report in the retrieved documents says that the %Net.POP3 implementation follows Microsoft’s OAuth POP approach, and that once you can correctly acquire and pass the access token, it should work. [3][4]

  3. Another important point is that POP access in Office 365 must be enabled, because one of the retrieved reports states that POP access is disabled by default on the Outlook 365 side. [3][4]

So, based on the retrieved material, the main correction to test in your case is this call:

Set status=server.Connect(servername,user,,AccessToken)

and make sure:

  • you are not sending the password with the token,
  • the token was requested with the POP scope,
  • the tenant ID is correct,
  • POP is enabled in Office 365. [1][2][3][4]

Your -ERR Authentication failure: unknown user name or bad password can therefore be caused by sending password + token together, using the wrong Connect() argument position, using an unsuitable scope set, or not having POP enabled on the Microsoft side. [1][2][3][4]


Sources:

Conte mais:
Não gosto do estilo
Não é factualmente correto
Não seguiu todas as instruções
Não deveria ter se recusado
Está sendo preguiçoso
Mais...
Enviar
0 0