Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bootstrapping oauth2 token #338

Open
kpedro88 opened this issue Mar 3, 2024 · 5 comments
Open

Bootstrapping oauth2 token #338

kpedro88 opened this issue Mar 3, 2024 · 5 comments

Comments

@kpedro88
Copy link

kpedro88 commented Mar 3, 2024

I am running davmail in headless (server) mode and using the O365Manual authentication mode. However, this requires some clunky switching back and forth between background and foreground when a new token needs to be obtained. The procedure seems to be:

  1. kill background instance of server
  2. start foreground instance of server
  3. prompt mail agent to send request to server to trigger authentication process
  4. copy/paste URLs back and forth
  5. kill foreground instance of server
  6. start background instance of server
  7. mail agent can then send requests silently again

Other oauth2 implementations that I've used provide a standalone script to obtain tokens (examples: https://github.com/tarickb/sasl-xoauth2/blob/master/scripts/sasl-xoauth2-tool.in, https://github.com/rlonstein/getmail/blob/master/getmail-gmail-xoauth-tokens, https://github.com/harishkrupo/oauth2ms). This would avoid the need for starting/stopping the server, or any foreground instances at all, or involving the mail agent. Whenever the server reports that it can no longer refresh the current token, we can just run the standalone script and get a new token.

In this case, the davmail.properties file could take arguments pointing to the location of each user's token file, rather than directly inserting the encoded refresh tokens.

I recognize that this is a non-trivial feature request, but it would make headless mode much smoother.

mguessan added a commit that referenced this issue Mar 10, 2024
…nt obtained refresh token, see #338

git-svn-id: https://svn.code.sf.net/p/davmail/code/trunk@3522 3d1905a2-6b24-0410-a738-b14d5a86fcbd
@mguessan
Copy link
Owner

Not a full answer to you request, but I added a -token command line option to just open the O365InteractiveAuthenticator and print refresh token on console

@mguessan
Copy link
Owner

mguessan commented Apr 9, 2024

If you combine davmail -token with the optional setting: davmail.oauth.tokenFilePath to set a separate file path for tokens you should be able to get seamless update of refresh tokens.

Note that for windows users I also published a powershell script as an alternative to davmail -token at:
https://github.com/mguessan/o365psauth
=> uses native webview2 (Chromium Edge)
=> supports windows single sign on with -SSO option

@kpedro88
Copy link
Author

kpedro88 commented May 6, 2024

Thanks for adding this feature!

I tried this with the new 6.2.2 build. davmail -token works, but once it refreshed the token, it stopped the already-running background instance of davmail and I had to restart it.

This also only works with the interactive authentication, which is slow when davmail is deployed on a headless server. Is it possible to make this work with O365Manual authentication, where the actual login can be conducted on a different machine?

@esabol
Copy link

esabol commented May 6, 2024

I tried this with the new 6.2.2 build. davmail -token works, but once it refreshed the token, it stopped the already-running background instance of davmail and I had to restart it.

That doesn't make any sense. How can davmail -token stop the already-running background instance of davmail? That's not the intention, surely, so it's a bug if that's what's happening.

Can you provide step-by-step instructions to reproduce this, @kpedro88 ?

Do you have davmail.oauth.tokenFilePath and davmail.oauth.persistToken set in your .davmail.properties file?

@kpedro88
Copy link
Author

kpedro88 commented May 6, 2024

  1. davmail.properties contains davmail.oauth.tokenFilePath and davmail.oauth.persistToken=true
  2. davmail .davmail/davmail.properties >& log_davmail.log &
  3. davmail .davmail/davmail.properties -token

I just tried again and it didn't stop the background process this time. The first time, I saw this after finishing step 3:

[1]+  Stopped                 davmail .davmail/davmail.properties &> log_davmail.log

Unfortunately the log file got overwritten. I'll keep checking to see if it happens again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants