It seems like login does not work with an access token generated through a readonly scope of gmail.
I am using LoginOAUTH2 and it seems it expects a full https://mail.google.com scope.
I only need to read emails so is there a way I can still make the code work with just readonly scope.
I don't think this is possible.
Gmail IMAP allows read/write access only, so as far as I know, Gmail requires full scope.