Guest User

Google yolo

a guest
May 3rd, 2018
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 3.32 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <title></title>
  5.     <script src="https://smartlock.google.com/client"></script>
  6.     </head>
  7. <body>
  8. <script type="text/javascript">
  9.  
  10.     window.onGoogleYoloLoad = (googleyolo) => {
  11.     //The 'googleyolo' object is ready for use.
  12.     const retrievePromise = googleyolo.retrieve({
  13.       supportedAuthMethods: [
  14.         "https://accounts.google.com",
  15.          "googleyolo://id-and-password"
  16.       ],
  17.       supportedIdTokenProviders: [
  18.         {
  19.           uri: "https://accounts.google.com",
  20.           clientId: "49545385213-jpl5edegp2hkqfjoedl5bqqo1dl07t06.apps.googleusercontent.com"
  21.         }
  22.       ]
  23.     });
  24.  
  25.     retrievePromise.then((credential) => {
  26.       if (credential.password) {
  27.         // An ID (usually email address) and password credential was retrieved.
  28.         // Sign in to your backend using the password.
  29.         signInWithEmailAndPassword(credential.id, credential.password);
  30.       } else {
  31.         // A Google Account is retrieved. Since Google supports ID token responses,
  32.         // you can use the token to sign in instead of initiating the Google sign-in
  33.         // flow.
  34.         console.log("token is ", credential.idToken);
  35.       }
  36.     }, (error) => {
  37.       // Credentials could not be retrieved. In general, if the user does not
  38.       // need to be signed in to use the page, you can just fail silently; or,
  39.       // you can also examine the error object to handle specific error cases.
  40.  
  41.       // If retrieval failed because there were no credentials available, and
  42.       // signing in might be useful or is required to proceed from this page,
  43.       // you can call `hint()` to prompt the user to select an account to sign
  44.       // in or sign up with.
  45.       console.log("error", error.type);
  46.       if (error.type === 'noCredentialsAvailable') {
  47.         console.log("only when no creds");
  48.     const hintPromise = googleyolo.hint({
  49.       supportedAuthMethods: [
  50.         "https://accounts.google.com"
  51.       ],
  52.       supportedIdTokenProviders: [
  53.         {
  54.           uri: "https://accounts.google.com",
  55.           clientId: "49545385213-jpl5edegp2hkqfjoedl5bqqo1dl07t06.apps.googleusercontent.com"
  56.         }
  57.       ]
  58.     });
  59.  
  60.     hintPromise.then((credential) => {
  61.         console.log("cred 1")
  62.       if (credential.idToken) {
  63.         console.log("cred 2")
  64.         console.log(credential);
  65.  
  66.       }
  67.     }, (error) => {
  68.       switch (error.type) {
  69.         case "userCanceled":
  70.           // The user closed the hint selector. Depending on the desired UX,
  71.           // request manual sign up or do nothing.
  72.           break;
  73.         case "noCredentialsAvailable":
  74.           // No hint available for the session. Depending on the desired UX,
  75.           // request manual sign up or do nothing.
  76.           break;
  77.         case "requestFailed":
  78.           // The request failed, most likely because of a timeout.
  79.           // You can retry another time if necessary.
  80.           break;
  81.         case "operationCanceled":
  82.           // The operation was programmatically canceled, do nothing.
  83.           break;
  84.         case "illegalConcurrentRequest":
  85.           // Another operation is pending, this one was aborted.
  86.           break;
  87.         case "initializationError":
  88.           // Failed to initialize. Refer to error.message for debugging.
  89.           break;
  90.         case "configurationError":
  91.           // Configuration error. Refer to error.message for debugging.
  92.           break;
  93.         default:
  94.           // Unknown error, do nothing.
  95.       } });
  96.  
  97.       }
  98.     });
  99.  
  100.  
  101.  };
  102. </script>
  103. <h1>Hello World</h1>
  104. </body>
  105. </html>
Add Comment
Please, Sign In to add comment