simonrob / email-oauth2-proxy

An IMAP/POP/SMTP proxy that transparently adds OAuth 2.0 authentication for email clients that don't support this method.
Apache License 2.0
786 stars 84 forks source link

Got JSONDecodeError #240

Closed Paolo-Erre closed 4 months ago

Paolo-Erre commented 4 months ago

Trying to access Exchange Online mailbox using Outlook in POP3 mode.

I used this tutorial to create AAD App Registration: https://github.com/lakelse/videos/tree/master/04-install-email-oauth2-proxy-youtube

And with this emailproxy.config:

[IMAP-1993]
server_address = outlook.office365.com
server_port = 993
local_address = 127.0.0.1

[POP-1995]
server_address = outlook.office365.com
server_port = 995
local_address = 127.0.0.1

[SMTP-1587]
server_address = smtp.office365.com
server_port = 587
server_starttls = True
local_address = 127.0.0.1

[###@###.###]
token_url = https://login.microsoftonline.com/###tenantID###/oauth2/v2.0/authorize
oauth2_scope = https://outlook.office365.com/.default
oauth2_flow = client_credentials
redirect_uri = http://localhost
client_id = ###clientID###
client_secret = ###clientSecret###

[emailproxy]
delete_account_token_on_password_error = True
encrypt_client_secret_on_first_use = False

I got the error (in emailproxy.log debug mode): Caught exception while requesting OAuth 2.0 credentials for ###@###.###: JSONDecodeError('Expecting value: line 3 column 1 (char 4)')

What's wrong?

Thanks, Paolo

simonrob commented 4 months ago

An invalid or unexpected response was provided by the server. This is the sort of thing that is best investigated via a test account in your O365. Is this something you can provide?

Paolo-Erre commented 4 months ago

 

Sent details to your mail.

 

Thanks,

Paolo

 

Sent: Thursday, April 04, 2024 at 5:26 PM From: "Simon Robinson" @.> To: "simonrob/email-oauth2-proxy" @.> Cc: "Paolo-Erre" @.>, "Author" @.> Subject: Re: [simonrob/email-oauth2-proxy] Got JSONDecodeError (Issue #240)

 

An invalid or unexpected response was provided by the server. This is the sort of thing that is best investigated via a test account in your O365. Is this something you can provide?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

simonrob commented 4 months ago

Thanks – in the end it was not something that required the test account, but a misconfiguration: you've used the wrong token url:

token_url = https://login.microsoftonline.com/###tenantID###/oauth2/v2.0/authorize

This value should be:

token_url = https://login.microsoftonline.com/###tenantID###/oauth2/v2.0/token

I.e., token rather than authorize. With this change, your test account works fine from my side.

Paolo-Erre commented 4 months ago

Yesss!!!

It's working now!

Thanks!