Developing a Chrome Extension Without URI Redirection

I am developing the Chrome extension, which is an open-source forked program on Github.com. The extension requires the Google Drive API, which requires an OAuth 2.0 client ID. However, when creating the client ID, I need to provide a redirect URI, but I do not have a redirect domain. Does this mean that I can’t use the Google Drive API or is there a workaround?

Thank!

+5
source share
3 answers

Yes, you can use the Drive API, but you need to use the Google JS client, just specify the scope, client ID, client secret and load the js client and make API calls. But the JavaScript source should have your chrome extension id (chrome-extension: // abcdefghijklmnopqrstuvwxyx)

The below features may be convenient for you.

// on client load call this function
var handleClientLoadAuto = function () {

    gapi.client.setApiKey(apiKey);
    window.setTimeout(checkAuthAuto, 1);
}

and

var checkAuthAuto = function () {
    gapi.auth.authorize({
        client_id: clientId,
        scope: 'scope here',
        immediate: true
    }, handleAuthResultAuto);
}

and if everything is fine:

var handleAuthResultAuto = function (authResult) {

    if (authResult && !authResult.error) {
        //do call to drive api using 
        gapi.client.load('drive', 'v2', function () {

                var request = gapi.client.drive.files.list(params);
                request.execute(function (resp) {
                    if (resp && resp.error) {
                        //call to error callback function
                        //handleError(resp);
                    } else {
                        //ok response
                    }

                });
            }
        } else {}
    }

But for this you need to log in, otherwise it will not detect authorization.

+2
source

You can simply use: http://localhosteverything should be fine.

The most important thing is to get a fingerprint, and then an API key.

+2
source

URI, :

https://<extension-id>.chromiumapp.org/<anything-here>

, , URL.

. :

https://developer.chrome.com/apps/app_identity#register_provider

, .

0

All Articles