Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title></title>
- <script src="https://smartlock.google.com/client"></script>
- </head>
- <body>
- <script type="text/javascript">
- window.onGoogleYoloLoad = (googleyolo) => {
- //The 'googleyolo' object is ready for use.
- const retrievePromise = googleyolo.retrieve({
- supportedAuthMethods: [
- "https://accounts.google.com",
- "googleyolo://id-and-password"
- ],
- supportedIdTokenProviders: [
- {
- uri: "https://accounts.google.com",
- clientId: "49545385213-jpl5edegp2hkqfjoedl5bqqo1dl07t06.apps.googleusercontent.com"
- }
- ]
- });
- retrievePromise.then((credential) => {
- if (credential.password) {
- // An ID (usually email address) and password credential was retrieved.
- // Sign in to your backend using the password.
- signInWithEmailAndPassword(credential.id, credential.password);
- } else {
- // A Google Account is retrieved. Since Google supports ID token responses,
- // you can use the token to sign in instead of initiating the Google sign-in
- // flow.
- console.log("token is ", credential.idToken);
- }
- }, (error) => {
- // Credentials could not be retrieved. In general, if the user does not
- // need to be signed in to use the page, you can just fail silently; or,
- // you can also examine the error object to handle specific error cases.
- // If retrieval failed because there were no credentials available, and
- // signing in might be useful or is required to proceed from this page,
- // you can call `hint()` to prompt the user to select an account to sign
- // in or sign up with.
- console.log("error", error.type);
- if (error.type === 'noCredentialsAvailable') {
- console.log("only when no creds");
- const hintPromise = googleyolo.hint({
- supportedAuthMethods: [
- "https://accounts.google.com"
- ],
- supportedIdTokenProviders: [
- {
- uri: "https://accounts.google.com",
- clientId: "49545385213-jpl5edegp2hkqfjoedl5bqqo1dl07t06.apps.googleusercontent.com"
- }
- ]
- });
- hintPromise.then((credential) => {
- console.log("cred 1")
- if (credential.idToken) {
- console.log("cred 2")
- console.log(credential);
- }
- }, (error) => {
- switch (error.type) {
- case "userCanceled":
- // The user closed the hint selector. Depending on the desired UX,
- // request manual sign up or do nothing.
- break;
- case "noCredentialsAvailable":
- // No hint available for the session. Depending on the desired UX,
- // request manual sign up or do nothing.
- break;
- case "requestFailed":
- // The request failed, most likely because of a timeout.
- // You can retry another time if necessary.
- break;
- case "operationCanceled":
- // The operation was programmatically canceled, do nothing.
- break;
- case "illegalConcurrentRequest":
- // Another operation is pending, this one was aborted.
- break;
- case "initializationError":
- // Failed to initialize. Refer to error.message for debugging.
- break;
- case "configurationError":
- // Configuration error. Refer to error.message for debugging.
- break;
- default:
- // Unknown error, do nothing.
- } });
- }
- });
- };
- </script>
- <h1>Hello World</h1>
- </body>
- </html>
Add Comment
Please, Sign In to add comment