skip to Main Content

When running my angular (ionic framework) app locally, via a browser all works well but when running via android studio or packaged and pushed into the mobile phone I get a 403.

This is on this line on the index.html:
<script src="https://accounts.google.com/gsi/client" async defer></script>

I am trying to integrate/implement "Sign In With Google" button as per this page: https://developers.google.com/identity/gsi/web/guides/client-library

Any pointers?

Thanks in advance!

2

Answers


  1. I have run into the same issue in REACT..

    the solution to my problem was to add /* global google */ above the google.accounts.id .

    /* global google */ by putting this line above our code, it will automatically refer to the script inside the index.html file.

    React.js example

    import './App.css';
    import { React, useEffect } from 'react'
    import jwt_decode from 'jwt-decode'
    
    function App() {
    
      function handleCallbackResponse(response) {
        var userObject = jwt_decode(response.credential);
        console.log(userObject);
      }
      useEffect(() => {
    
        /* global google */  <-- Add this line before calling google.accounts.id
    
        google.accounts.id.initialize({
         client_id: "Your Client ID here",
         callback: handleCallbackResponse
        })
    
        google.accounts.id.renderButton(
         document.getElementById("signInDiv"),
          { theme: "outline", size: "large" }
        );
    
        return () => {
        }
      }, [])
    
    
      return (
       <div className="App">
       <div id="signInDiv"></div>
       </div>
      );
    }
    
    export default App;
    
    Login or Signup to reply.
  2. The error can be removed by setting another user agent. It can be done as follows for Ionic with capacitor.

    public class MainActivity extends BridgeActivity {
      @Override
      public void onStart() {
        super.onStart();
        var webView = getBridge().getWebView();
        var settings = webView.getSettings();
        settings.setUserAgentString("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36");
      }
    }
    

    However the one-tap web library is still not working properly on android. You can search for

    Google Sign In does not support web view.

    to find more information.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search