Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OAuth consent screen localhost

I am trying to use Gmail API javascript code to access others email, code is as below :-

function authenticate() {
        return gapi.auth2.getAuthInstance()
            .signIn({ scope: "https://mail.google.com/ https://www.googleapis.com/auth/gmail.compose https://www.googleapis.com/auth/gmail.modify https://www.googleapis.com/auth/gmail.readonly" })
            .then(function () { console.log("Sign-in successful"); },
                function (err) { console.error("Error signing in", err); });
    }
    function loadClient() {
        return gapi.client.load("https://content.googleapis.com/discovery/v1/apis/gmail/v1/rest")
            .then(function () { console.log("GAPI client loaded for API"); },
                function (err) { console.error("Error loading GAPI client for API", err); });
    }
    // Make sure the client is loaded and sign-in is complete before calling this method.
    function execute() {
        return gapi.client.gmail.users.getProfile({})
            .then(function (response) {
                // Handle the results here (response.result has the parsed body).
                console.log("Response", response);
            },
                function (err) { console.error("Execute error", err); });
    }
    gapi.load("client:auth2", function () {
        gapi.auth2.init({ client_id: "681860637449-ar2gfuhr23nf88h2ct7b5fs0oh213a0n.apps.googleusercontent.com" });
    });

Here i am facing difficulty regarding This app isn't verified when i try to access other email here are the screen shots for
1. Consent Screen(URL published)
2. Gmail Login(Logged in from javascript code)
3. App not verfified

1. Consent Screen
2. Gmail Login
3. App not verified

like image 530
namco Avatar asked Oct 28 '25 11:10

namco


1 Answers

Not sure if this will help others, but adding http://localhost under "URIs" as below worked for me, on an app marked as Internal through the Google Cloud Console.

  1. If your app is not "internal", you will have to go through a manual verification step from what I have read - don't know anything about this, my app is internal
  2. To get around the localhost issue, adding the host to the Credentials config as opposed to the OAuth2 consent screen config seems to have worked for me, at least with my web app on localhost retrieving a Google Sheet (config not intuitive because the domain validations differ between the two GCP settings pages): enter image description here
like image 162
JHS Avatar answered Oct 31 '25 00:10

JHS



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!