This url explains how oauth works
https://developers.google.com/identity/protocols/oauth2/web-server
NEED to set the end point for any gmail users here :-
https://developers.google.com/gmail/imap/xoauth2-libraries
DONT USE SERVICE ACCOUNT
instead use
the gmail client id