README_OAUTH2.txt 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # $Id: README_OAUTH2.txt,v 1.2 2022/07/25 16:44:43 gilles Exp gilles $
  2. 1) Do you have a refresh_token?
  3. Yes: Good!
  4. No: Get one. How? Run the commands:
  5. cd oauth2/
  6. ./generate_gmail_token youremail@gmail.com
  7. You will be asked to go to a long url with a browser, like this:
  8. To authorize token, visit this url and follow the directions:
  9. https://accounts.google.com/o/oauth2/auth?client_id=108687549524-86sjq07f3ch8otl9fnr56mjnniltdrvn.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&scope=https%3A%2F%2Fmail.google.com%2F
  10. Go to this url, the url above should be the same as presented by the script.
  11. Select your gmail address on the page, maybe do some 2-steps confirmation
  12. with your phone. Then you'll see this warning:
  13. "Google hasn’t verified this app"
  14. "The app is requesting access to sensitive info in your Google Account.
  15. Until the developer (gilles.lamiral@gmail.com) verifies this app
  16. with Google, you shouldn't use it."
  17. Well, gilles.lamiral@gmail.com is me and I haven't verify this app
  18. with google yet. But it's me Gilles LAMIRAL, the imapsync author.
  19. Click on the link "Advanced".
  20. It writes:
  21. "Continue only if you understand the risks and trust the developer (gilles.lamiral@gmail.com)."
  22. Then click on the link "Go to imapsync (unsafe)"
  23. It then shows:
  24. "imapsync wants to access your Google Account"
  25. "Make sure you trust imapsync"
  26. "You may be sharing sensitive info with this site or app.
  27. You can always see or remove access in your Google Account."
  28. Click on the blue button "Allow"
  29. Copy/paste the code after the prompt "Enter verification code: "
  30. It will generate a refresh token, an access token, and an oauthdirect
  31. token shown on the output, saved in three files,
  32. one file named ./D_oauth2_refresh_token_youremail@gmail.com.txt
  33. another named ./D_oauth2_access_token_youremail@gmail.com.txt
  34. another named ./D_oauth2_oauthdirect_youremail@gmail.com.txt
  35. The refresh_token is just there to refresh the access_token and the
  36. oauthdirect token.
  37. With imapsync you can use either the oauthdirect or the access_token
  38. token, like this:
  39. imapsync ... --user1 useless --oauthdirect1 oauth2/D_oauth2_oauthdirect_youremail@gmail.com.txt
  40. imapsync ... --user1 youremail@gmail.com --oauthaccesstoken1 oauth2/D_oauth2_access_token_youremail@gmail.com.txt
  41. With --oauthdirect1 the --user1 parameter is useless because it is already
  42. coded inside the oauthdirect token.
  43. With --oauthaccesstoken1 the --user1 parameter is important because it will be
  44. used by imapsync to generate the oauthdirect token.
  45. 2) How to get a fresh enough access_token (less than one hour)?
  46. Run the same command:
  47. cd oauth2/
  48. ./generate_gmail_token youremail@gmail.com
  49. It will generate a new access_token (and the oauthdirect one)
  50. without any prompt this time, because the refresh token is used for that.