Skip to content

Latest commit

 

History

History
86 lines (54 loc) · 4.35 KB

Authentication.md

File metadata and controls

86 lines (54 loc) · 4.35 KB

Authentication

This package requires the following environment variables to be set:

  • GOOGLE_CLIENT_ID
  • GOOGLE_CLIENT_SECRET
  • GOOGLE_REFRESH_TOKEN

Below is a step-by-step of how to get the values to correctly fill those variables:

Note: the names you enter below don't really matter, so you can just put whatever you feel comfortable with.

  1. Visit the Google API Console.

  2. Create new project:

    chrome-apis-create-project
  3. Enter a name and click Create. This can take some seconds, and Google will notify you when it's done.

  4. Visit the Google API Console again.

  5. Enable the API, clicking on the button Enable:

    chrome-apis-enable-webstore
  6. On the page that opened, search for Chrome Web Store API, and enable it.

  7. Open Credentials > Create credentials > OAuth client ID:

    create-credentials
  8. Click on Configure consent screen:

    configure consent screen
  9. Enter a product name and save.

  10. Select Other and click Create:

    client type id
  11. A new modal opens, with two fields, the first containing a client ID, and the second containing a client secret. Save those values, as we are going to need them later.

  12. In the following URL, replace <YOUR_CLIENT_ID> with the value of your client ID, and open it:

    https://accounts.google.com/o/oauth2/auth?client_id=<YOUR_CLIENT_ID>&response_type=code&scope=https://www.googleapis.com/auth/chromewebstore&redirect_uri=urn:ietf:wg:oauth:2.0:oob

  13. Follow the steps shown on the screen and, on the last page, you will see another code which is the auth code. Save this value, as we will also use it later.

    auth code
  14. Run this in your browser's console.
    It's just a wizard to create and copy a curl into your clipboard:

    var clientId = 'YOUR CLIENT ID HERE'
    var clientSecret = 'YOUR CLIENT SECRET HERE'
    var authCode = 'YOUR AUTH CODE HERE'
    
    copy(
      `curl "https://accounts.google.com/o/oauth2/token" -d "client_id=${encodeURIComponent(
        clientId,
      )}&client_secret=${encodeURIComponent(
        clientSecret,
      )}&code=${encodeURIComponent(
        authCode,
      )}&grant_type=authorization_code&redirect_uri=urn:ietf:wg:oauth:2.0:oob"`,
    )
    
    console.log('The curl has been copied. Paste it into your terminal.')
  15. Paste the generated code in your terminal and run it. If your terminal doesn't natively support curl, try using the git bash terminal instead, or use online curl. You can also manually install curl, if none of options before worked.

  16. The curl command will give you This will give you an object which looks like the following:

    access token

    From this object, the only important information is the refresh_token, so it is important to save this value as, you guessed it, we are going to need it later.

  17. You should have now a client ID, a client secret, and a refresh_token. Use them to set the following environment values:

    • GOOGLE_CLIENT_ID: set the value to client ID.
    • GOOGLE_CLIENT_SECRET: set the value to client secret
    • GOOGLE_REFRESH_TOKEN: set the value to refresh_token

Now you should have all three environment variables correctly set. You can use the same values for all your extensions, but remember not share them publicly, as they will allow anyone to publish your extensions!