imapfilter icon indicating copy to clipboard operation
imapfilter copied to clipboard

allow callback from C code to lua to refresh OAuth2 token

Open rhaas80 opened this issue 3 years ago • 0 comments

OAuth2 tokens expire after a while and need to be refreshed using the refresh token.

This means that if one uses options.recover = true and imapfilter tries to recover due to an authentication failure it should try and use a refreshed token rather than the one copied during the initial login.

Right now there is no way for C to call back to Lua. I would like to propose (and am willing to code up an example) of a lua callback functionality that would eg add an option

Account.oauth2_refresh = fucntion() return new_token end

that lets one register a callback function that returns the new token to the C code.

Mostly following the ideas outlined in https://www.appsloveworld.com/c/100/12/store-a-lua-function and the "Calling Lua functions from C/C++" section in https://www.cs.usfca.edu/~galles/cs420/lecture/LuaLectures/LuaAndC.html

Would this be something that would stand a chance of inclusion? It changes imapfilters data flow a bit since it no longer is strictly from Lua to the C of imapfilter.

rhaas80 avatar Aug 17 '22 19:08 rhaas80