Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve a never ending loop of login screens when trying to OAuth in chrome extension?

Trying to learn oauth for my chrome extension using identity api.

I have uploaded code to https://github.com/Sandeep3005/learn-oauth-extension

Issue :
When background file runs - it opens a new tab with Gmail login page.But even I provide right credentials login page keep appear again and again and I have to force quit Chrome.

A solution provided at
Stack Overflow Solution - mentions this occurs when app-ID in chrome is different at app-ID in https://console.developers.google.com.
But I checked and rechecked it.Both values of app-ID is exact.
Can anybody guide me on this.

manifest.json

     {
       "manifest_version": 2,
       "name": "outh-test-2",
       "short_name": "outh-test-2",
       "description": "Description for outh-test-2",
       "version": "1.0",
       "background": { "scripts": [ "background.js" ], "persistent": true },
       "content_scripts": [
        {
           "run_at": "document_end",
           "matches": [
              "https://www.dominos.co.in/",
              "https://en.wikipedia.org/*"
            ],
            "js": [ "content.js" ]
        }
       ],
       "permissions": [
          "identity"
       ],
       "oauth2": {
          "client_id": "574710815026-blt94u58ie7jqqanuc73b49mdaqrp9j4.apps.googleusercontent.com",
          "scopes": [
            "http://www.googleapis.com/auth/drive"
          ]
       },
       "key":"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmRBFelCyG27kHcy38C/bZXggBPDV3JyKnsunJDfHotUG9QQI6Z+KzoeEdCKK/GvQe7AGTNkkr3FUATGmR1b5MbjzTx90qzg6xsrXSU7mqBgJwYPny+PW46pGRwMSz4FEcLO1vUKD9kIhpSzi+0RJv1IwDx6/SNeQzOxXR5B7dWXTKtbiD9f9Rd5yj9Qfy1Q76iIc8P6afpO1DgT960+yZV4+12tCoC+GZILvK3GBwC0vhkeVsIMWaNkIIzC/0PcbLis2HrfZz6iHcetcv4aY6MAIfQWBxaFbDiXXIhXSvi9zO00w/mc9hLxls4fcivXZdEowgEu0UV4+EJuzL35s2wIDAQAB"
    }

background.js

console.log('Welcome to background Page');

console.log('chrome Identity  = ', chrome.identity);

chrome.identity.getAuthToken({ interactive: true }, function (token) {
 if (chrome.runtime.lastError) {
  callback(chrome.runtime.lastError);
  return;
 }
 access_token = token;
});

Steps I followed
1. Created basic chrome extension with client-id and key values missing

2.Upload ziped extension file to https://chrome.google.com/webstore/developer/dashboard

3.Copied public-key and item-id.

4.Create new project at google developer console

5.
a)Create credentials for OAuth Client ID
b)Picked Chrome App as application type
c)Inserted Item-ID I got from webstore developer dashboard in application-ID text field
d)Got Client-ID in return.

6) Copied this client-ID in manifest.json file and also inserted pulic key here.

Wrote code for background.js and ran extension on chrome and boom - I am inside a loop where google ask for email password again, again and again...

Please guide me on this

like image 943
Sandeep Chikhale Avatar asked Jan 20 '18 12:01

Sandeep Chikhale


People also ask

How do I add OAuth extension to Chrome?

# Create OAuth client ID Once ready, select Credentials in the sidebar, click Create credentials and choose OAuth client ID. On the Create client ID page, select Chrome App. Fill out the name of the extension and place the extension ID at the end of the URL in the Application ID field. Finish by clicking create.


1 Answers

As the documentation states, the scope you need is:

https://www.googleapis.com/auth/drive

You wrote http://www.googleapis.com/auth/drive but it must be https.

like image 109
Iván Nokonoko Avatar answered Oct 19 '22 09:10

Iván Nokonoko