Skip to content

Commit

Permalink
Remove redundant clientSecret variable
Browse files Browse the repository at this point in the history
  • Loading branch information
tuanddd committed Dec 29, 2020
1 parent 2444502 commit 6810a72
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 14 deletions.
13 changes: 6 additions & 7 deletions How to generate Google API keys.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[chrome-webstore-upload](https://github.com/DrewML/chrome-webstore-upload) uses the Chrome Web Store API.

Here's how to get its 3 access keys: `clientId`, `clientSecret`, `refreshToken`
Here's how to get its 2 access keys: `clientId`, `refreshToken`

*Note:* the names you enter here don't really matter. This will take approximately 10 minutes, sorry.

Expand All @@ -25,14 +25,14 @@ Here's how to get its 3 access keys: `clientId`, `clientSecret`, `refreshToken`

<img width="771" alt="Create credentials" src="https://user-images.githubusercontent.com/1402241/77865679-e89f3a00-722f-11ea-942d-5245091f22b8.png">

0. Select **Other** (or **Desktop app** if available), enter `chrome-webstore-upload` and click **Create**
0. Select **Chrome App** (or **Desktop app** if available), enter `chrome-webstore-upload` and click **Create**

> <img width="187" alt="Configure client type" src="https://cloud.githubusercontent.com/assets/1402241/21517952/d1f36fce-cc97-11e6-92c0-de4485d97736.png">
> <img width="187" alt="Configure client type" src="https://user-images.githubusercontent.com/25856620/103254672-d1f16380-49b8-11eb-8cdf-98c2483be403.png">

0. Save your ✅ `clientId` and ✅ `clientSecret`, these are your 2 of your 3 keys.
0. Save your ✅ `clientId`, this is your 1 of your 2 keys.
0. Place your `clientId` in this URL 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`
`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&access_type=offline&approval_prompt=force`

0. Follow its steps and warnings (this is your own peronal app) and wait on the last page:

Expand All @@ -45,7 +45,6 @@ response = await fetch('https://accounts.google.com/o/oauth2/token', {
method: "POST",
body: new URLSearchParams([
['client_id', prompt('Enter your clientId')],
['client_secret', prompt('Enter your clientSecret')],
['code', new URLSearchParams(location.search).get('approvalCode')],
['grant_type', 'authorization_code'],
['redirect_uri', 'urn:ietf:wg:oauth:2.0:oob']
Expand All @@ -67,4 +66,4 @@ if (!json.error) {
}
```

9001. Done. Now you should have ✅ `clientId`, ✅ `clientSecret` and ✅ `refreshToken`. You can use these for all your extensions, but don't share them!
9001. Done. Now you should have ✅ `clientId` and ✅ `refreshToken`. You can use these for all your extensions, but don't share them!
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ npm install --save-dev chrome-webstore-upload

## Setup

You will need a Google API `clientId`, a `clientSecret` and a `refreshToken`. Read [the guide](./How%20to%20generate%20Google%20API%20keys.md).
You will need a Google API `clientId` and a `refreshToken`. Read [the guide](./How%20to%20generate%20Google%20API%20keys.md).

## Usage

Expand All @@ -24,7 +24,6 @@ All methods return an ES2015-compliant promise.
const webStore = require('chrome-webstore-upload')({
extensionId: 'ecnglinljpjkbgmdpeiglonddahpbkeb',
clientId: 'xxxxxxxxxx',
clientSecret: 'xxxxxxxxxx',
refreshToken: 'xxxxxxxxxx'
});
```
Expand Down
4 changes: 1 addition & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const publishURI = (id, target) => (
const requiredFields = [
'extensionId',
'clientId',
'clientSecret',
'refreshToken'
];

Expand Down Expand Up @@ -47,12 +46,11 @@ class APIClient {
}

async fetchToken() {
const { clientId, clientSecret, refreshToken } = this;
const { clientId, refreshToken } = this;

const response = await got.post(refreshTokenURI, {
json: {
client_id: clientId,
client_secret: clientSecret,
refresh_token: refreshToken,
grant_type: 'refresh_token'
}
Expand Down
2 changes: 1 addition & 1 deletion test/fetchToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ test.serial('Only returns token from response body', async t => {
t.is(await client.fetchToken(), accessToken);
});

test.todo('Request includes clientId, clientSecret, and refreshToken');
test.todo('Request includes clientId, and refreshToken');
1 change: 0 additions & 1 deletion test/helpers/get-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ module.exports = function getClient() {
return webStoreUpload({
extensionId: 'foo',
clientId: 'bar',
clientSecret: 'foobar',
refreshToken: 'heyhey'
});
};

0 comments on commit 6810a72

Please sign in to comment.