Looking for OAuth2 javascript example

I am looking into using the Google Drive API using only bearer and refresh tokens.

Therefore, what I am looking for is a sample script in javascript that takes the OAuth2 flow from client secret and Client ID and goes through the process of getting an authorization code and then exchanging this authorization code for a bearer and refresh token. I’ve heard the refresh token never expires (until revoked) so then the plan is to use these in an automated backup script to backup to Google drive.

I am only looking for a javascript code to take me to the bearer and refresh token output in the browser. I don’t need it to do the backup. I will use a seperate script for that. Any ideas on where to find such a script? I could probably write one in time but I’m trying not to reinvent the wheel.

Something like this?