This describes the pattern for sidebars and dialog boxes using the Goa library as described in Oauth2 for Apps Script in a few lines of code (which you should read first for background).
If you have initialized the credentials as described in Goa Setup, you are now ready to set your app for an authentication dialog. If you are using the service account flow there is no need for this. In fact, once you have run this once for you script you won't need to run it again.
With the doGet() webapp pattern, returning the goa.getConsent() dialog if one is needed, is followed by returning the result of your application as HtmlOutput to be rendered by the published app.
For a sidebar, the pattern is almost the same, except that another sidebar call is used to render the result as below.
When using a sidebar, the consent dialog created by Goa is rendered in the sidebar. When the Google Auth dialog initiates it does so in a separate browser tab. I haven't yet found a way of making that happen in the sidebar, with the result that you get an untidy message in a tab that can just be closed.
The script completed but did not return anything.
If anyone can find a way of closing this tab post-authentication, I'd be interested in your thoughts.
Learning Apps Script, (and transitioning from VBA) are covered comprehensively in my my book, Going Gas - from VBA to Apps script, All formats are available from O'Reilly, Amazon and all good bookshops. You can also read a preview on O'Reilly
Services > Desktop Liberation - the definitive resource for Google Apps Script and Microsoft Office automation > OAuth2 for Apps Script in a few lines of code >