Page Summary
-
The Google 3P Authorization JavaScript library is required for pages handling OAuth 2.0 codes or tokens and can be loaded using a provided script snippet.
-
Loading the script with
asyncanddeferattributes can optimize page loading speed.
Be sure to load the Google Identity Services JavaScript library
(https://accounts.google.com/gsi/client) on any web page where a user might
initiate an OAuth 2.0 authorization flow to obtain authorization codes or access
tokens. Use the following <script> snippet in your HTML <head> or <body>:
<script src="https://accounts.google.com/gsi/client" async></script>
You can optimize your page's loading speed by loading the script with the
async attribute. If your script initializes a token client
(google.accounts.oauth2.initTokenClient) or code client
(google.accounts.oauth2.initCodeClient) immediately upon load, you can attach
an onload callback handler to the <script> tag:
<script src="https://accounts.google.com/gsi/client" onload="initClient()" async></script>
Refer to the Google Account Authorization JavaScript API reference for the
complete list of methods and configuration properties that the
google.accounts.oauth2 namespace supports.
Next steps
After loading the client library, choose the authorization model that matches your application architecture:
- Choose a user authorization model to compare the authorization code and implicit grant flows.
- Use the authorization code model (recommended for apps with a backend server).
- Use the token model (for client-side, browser-only apps).