How To Implement Google Authenticator Two Factor Auth in JavaScript

How To Implement Google Authenticator Two Factor Auth in JavaScript

Google Authenticator is something that many of us use all the time but how many of us really understand how it works under the hood?