[]
Initializes a new instance of the OAuth2 class.
For details on the apiKey, clientID, and scope parameters, please refer to https://developers.google.com/identity/sign-in/web/sign-in.
To create or edit application credentials, please refer to https://console.developers.google.com/apis/credentials.
For a list of OAuth2 scopes for Google APIs, please refer to https://developers.google.com/identity/protocols/oauth2/scopes
An API key string created at Google's credentials page.
A client ID string created at Google's credentials page.
An array of strings representing OAuth2 scopes required by the application.
JavaScript object containing initialization data for the object.
Gets an OAuth access token that can be used to perform authorized requests.
Gets an OAuth id token that can be passed to the Firebase client libraries.
See https://firebase.google.com/docs/auth/web/google-signin
let credential = firebase.auth.GoogleAuthProvider.credential(id_token);
firebase.auth().signInWithCredential(credential);
Gets an object with information about the current user (or null if the user is not signed-in).
Raises the error event.
Raises the userChanged event.
Signs a user in.
Signs a user out.
Occurs when an error happens.
Occurs when a user signs in or out.
since version 5.20231.* Please use Google's own authentication methods.
Provides a simple way to use Google's GAPI OAuth functionality.
To use, create an instance of the OAuth2 class and add a handler to the userChanged event to monitor the {@link @user} property, which is non-null if a user is currently signed in.
Use the signIn and signOut methods to sign in or out of the Google account.
For example, the code below creates an OAuth2 object and uses it to manage a button used to log users in and out of the application:
import { OAuth2 } from '@mescius/wijmo.cloud'; // create OAuth2 object const API_KEY = 'XXXX'; const CLIENT_ID = 'YYYY.apps.googleusercontent.com'; const SCOPES = [ 'https://www.googleapis.com/auth/userinfo.email' ]; const auth = new OAuth2(API_KEY, CLIENT_ID, SCOPES); // click a button to log in/out let oAuthBtn = document.getElementById('auth_btn'); oAuthBtn.addEventListener('click', () => { if (auth.user) { auth.signOut(); } else { auth.signIn(); } }); // update button caption and accessToken when user changes auth.userChanged.addHandler(s => { let user = s.user; oAuthBtn.textContent = user ? 'Sign Out' : 'Sign In'; gsNWind.accessToken = user ? s.accessToken : null; fsNWind.accessToken = user ? s.accessToken : null; });