chrome-webstore-upload-keys 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci.yml +21 -0
- package/cli.js +154 -0
- package/demo.gif +0 -0
- package/license +10 -0
- package/package.json +38 -0
- package/readme.md +68 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
on:
|
|
3
|
+
- push
|
|
4
|
+
- pull_request
|
|
5
|
+
jobs:
|
|
6
|
+
test:
|
|
7
|
+
name: Node.js ${{ matrix.node-version }}
|
|
8
|
+
runs-on: ubuntu-latest
|
|
9
|
+
strategy:
|
|
10
|
+
fail-fast: false
|
|
11
|
+
matrix:
|
|
12
|
+
node-version:
|
|
13
|
+
- 20
|
|
14
|
+
- 18
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
- uses: actions/setup-node@v4
|
|
18
|
+
with:
|
|
19
|
+
node-version: ${{ matrix.node-version }}
|
|
20
|
+
- run: npm install
|
|
21
|
+
- run: npm test
|
package/cli.js
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import process from 'node:process';
|
|
3
|
+
import {createServer} from 'node:http';
|
|
4
|
+
import * as p from '@clack/prompts';
|
|
5
|
+
import open from 'open';
|
|
6
|
+
import getPort from 'get-port';
|
|
7
|
+
import pDefer from 'p-defer';
|
|
8
|
+
|
|
9
|
+
const approvalCode = pDefer();
|
|
10
|
+
const port = await getPort();
|
|
11
|
+
const localhost = '127.0.0.1';
|
|
12
|
+
|
|
13
|
+
// TODO: Remove after https://github.com/natemoo-re/clack/issues/181
|
|
14
|
+
const tasks = async tasks => {
|
|
15
|
+
for (const task of tasks) {
|
|
16
|
+
if (task.enabled === false) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const s = p.spinner();
|
|
21
|
+
s.start(task.title);
|
|
22
|
+
// eslint-disable-next-line no-await-in-loop -- Sequential
|
|
23
|
+
const result = await task.task(s.message);
|
|
24
|
+
s.stop(result || task.title);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const server = createServer((request, response) => {
|
|
29
|
+
const {searchParams} = new URL(request.url, serverUrl);
|
|
30
|
+
if (searchParams.has('code')) {
|
|
31
|
+
approvalCode.resolve(searchParams.get('code'));
|
|
32
|
+
// Html header
|
|
33
|
+
response.writeHead(200, {'Content-Type': 'text/html'});
|
|
34
|
+
response.end('You can close this tab now. <script>window.close()</script>');
|
|
35
|
+
server.close();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
response.writeHead(400, {'Content-Type': 'text/plain'});
|
|
40
|
+
response.end('No `code` found in the URL. WHO R U?');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Start the server on port 3000
|
|
44
|
+
server.listen(port, localhost);
|
|
45
|
+
|
|
46
|
+
const serverUrl = `http://${localhost}:${port}`;
|
|
47
|
+
|
|
48
|
+
function required(input) {
|
|
49
|
+
if (input.trim() === '') {
|
|
50
|
+
return 'Required';
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function getRefreshToken() {
|
|
55
|
+
const request = await fetch('https://accounts.google.com/o/oauth2/token', {
|
|
56
|
+
method: 'POST',
|
|
57
|
+
body: new URLSearchParams([
|
|
58
|
+
['client_id', group.clientId],
|
|
59
|
+
['client_secret', group.clientSecret],
|
|
60
|
+
['code', code],
|
|
61
|
+
['grant_type', 'authorization_code'],
|
|
62
|
+
['redirect_uri', serverUrl], // Unused but required
|
|
63
|
+
]),
|
|
64
|
+
headers: {
|
|
65
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
if (!request.ok) {
|
|
70
|
+
throw new Error('Error while getting the refresh token: ' + request.statusText);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const response = await request.json();
|
|
74
|
+
|
|
75
|
+
if (response.error) {
|
|
76
|
+
throw new Error('Error while getting the refresh token: ' + response.error);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return response.refresh_token;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function getLoginUrl(clientId) {
|
|
83
|
+
const url = new URL('https://accounts.google.com/o/oauth2/auth');
|
|
84
|
+
url.searchParams.set('response_type', 'code');
|
|
85
|
+
url.searchParams.set('access_type', 'offline');
|
|
86
|
+
url.searchParams.set('client_id', clientId);
|
|
87
|
+
url.searchParams.set('scope', 'https://www.googleapis.com/auth/chromewebstore');
|
|
88
|
+
url.searchParams.set('redirect_uri', serverUrl);
|
|
89
|
+
return url.href;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
p.intro('Follow the steps at this URL to generate the API keys, then enter them below to generate the refresh token.\n https://github.com/fregante/chrome-webstore-upload-keys');
|
|
93
|
+
const group = await p.group(
|
|
94
|
+
{
|
|
95
|
+
// ExtensionId: () => p.text({
|
|
96
|
+
// message: 'Extension ID:',
|
|
97
|
+
// placeholder: 'e.g. bdeobgpddfaegbjfinhldnkfeieakdaf, it’s in the Chrome Web Store URL',
|
|
98
|
+
// }),
|
|
99
|
+
clientId: () => p.text({
|
|
100
|
+
message: 'Client ID:',
|
|
101
|
+
placeholder: 'e.g. 960453266371-2qcq5fppm3d5e.apps.googleusercontent.com',
|
|
102
|
+
validate: required,
|
|
103
|
+
}),
|
|
104
|
+
clientSecret: () => p.text({
|
|
105
|
+
message: 'Client secret:',
|
|
106
|
+
placeholder: 'e.g. GOCSPX-O9uS1FLnCqXDvru7Y_',
|
|
107
|
+
validate: required,
|
|
108
|
+
}),
|
|
109
|
+
open: () => p.confirm({
|
|
110
|
+
message: 'Open the authentication page in the default browser?',
|
|
111
|
+
}),
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
onCancel() {
|
|
115
|
+
p.cancel('Operation cancelled.');
|
|
116
|
+
process.exit(0); // `onCancel` continues to the next question
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
let code;
|
|
122
|
+
let refreshToken;
|
|
123
|
+
await tasks([
|
|
124
|
+
{
|
|
125
|
+
title: 'Opening the login page in the browser',
|
|
126
|
+
async task() {
|
|
127
|
+
if (group.open) {
|
|
128
|
+
await open(getLoginUrl(group.clientId));
|
|
129
|
+
return 'Page opened';
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return 'Continue in: ' + getLoginUrl(group.clientId);
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
title: 'Waiting for you to complete the process in the browser. Follow its steps and warnings (this is your own personal app)',
|
|
137
|
+
async task() {
|
|
138
|
+
code = await approvalCode.promise;
|
|
139
|
+
return 'Approval code received from Google';
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
title: 'Asking Google for the refresh token',
|
|
144
|
+
async task() {
|
|
145
|
+
refreshToken = await getRefreshToken();
|
|
146
|
+
return `Done:
|
|
147
|
+
|
|
148
|
+
CLIENT_ID=${group.clientId}
|
|
149
|
+
CLIENT_SECRET=${group.clientSecret}
|
|
150
|
+
REFRESH_TOKEN=${refreshToken}
|
|
151
|
+
`;
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
]);
|
package/demo.gif
ADDED
|
Binary file
|
package/license
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) Federico Brigante <me@fregante.com> (https://fregante.com)
|
|
4
|
+
Copyright (c) 2020 Andrew Levine
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
7
|
+
|
|
8
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
9
|
+
|
|
10
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "chrome-webstore-upload-keys",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "CLI tool to generate OAuth keys for the Chrome Web Store",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"chrome",
|
|
7
|
+
"publish",
|
|
8
|
+
"webstore",
|
|
9
|
+
"store",
|
|
10
|
+
"extension",
|
|
11
|
+
"deploy",
|
|
12
|
+
"update",
|
|
13
|
+
"upload",
|
|
14
|
+
"cli"
|
|
15
|
+
],
|
|
16
|
+
"repository": "fregante/chrome-webstore-upload-keys",
|
|
17
|
+
"funding": "https://github.com/sponsors/fregante",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"author": "Federico Brigante <me@fregante.com> (https://fregante.com)",
|
|
20
|
+
"type": "module",
|
|
21
|
+
"bin": "cli.js",
|
|
22
|
+
"scripts": {
|
|
23
|
+
"test": "xo",
|
|
24
|
+
"start": "./cli.js"
|
|
25
|
+
},
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=18"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@clack/prompts": "^0.7.0",
|
|
31
|
+
"get-port": "^7.0.0",
|
|
32
|
+
"open": "^9.1.0",
|
|
33
|
+
"p-defer": "^4.0.0"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"xo": "^0.56.0"
|
|
37
|
+
}
|
|
38
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# How to generate Google API keys
|
|
2
|
+
|
|
3
|
+
> Guide and OAuth helper to generate keys
|
|
4
|
+
|
|
5
|
+
Companion to [Web Store Upload](https://github.com/fregante/chrome-webstore-upload).
|
|
6
|
+
|
|
7
|
+
You can follow this complete guide or the official-but-partial one at: https://developer.chrome.com/docs/webstore/using-api
|
|
8
|
+
|
|
9
|
+
> [!TIP]
|
|
10
|
+
> The names you enter here don't really matter. It's an app that only you will have access to. This will take approximately 10 minutes and Google likes to change these screens often. Sorry.
|
|
11
|
+
|
|
12
|
+
1. Visit https://console.developers.google.com/apis/credentials
|
|
13
|
+
0. Create a project:
|
|
14
|
+
|
|
15
|
+
> <img width="772" alt="Google APIs: Create project" src="https://user-images.githubusercontent.com/1402241/77865620-9a8a3680-722f-11ea-99cb-b09e5c0c11ec.png">
|
|
16
|
+
|
|
17
|
+
0. Enter `chrome-webstore-upload` and **Create**
|
|
18
|
+
0. Visit https://console.cloud.google.com/apis/credentials/consent
|
|
19
|
+
0. Select on **External** and **Create**
|
|
20
|
+
|
|
21
|
+
> <img width="804" alt="OAuth Consent Screen" src="https://user-images.githubusercontent.com/1402241/133878019-f159f035-2b76-4686-a461-0e0005355da6.png">
|
|
22
|
+
|
|
23
|
+
0. Only enter the Application name (e.g. `chrome-webstore-upload`) and required email fields, and click **Save**
|
|
24
|
+
|
|
25
|
+
> <img width="475" alt="Consent screen configuration" src="https://user-images.githubusercontent.com/1402241/77865809-82ff7d80-7230-11ea-8a96-e381d55524c5.png">
|
|
26
|
+
|
|
27
|
+
0. On the 3rd screen, add your own email address:
|
|
28
|
+
|
|
29
|
+
> <img width="632" alt="Test users selection" src="https://user-images.githubusercontent.com/1402241/106213510-7c180300-6192-11eb-97b4-b4ae92424bf1.png">
|
|
30
|
+
|
|
31
|
+
0. Visit https://console.developers.google.com/apis/library/chromewebstore.googleapis.com
|
|
32
|
+
0. Click **Enable**
|
|
33
|
+
0. Visit https://console.developers.google.com/apis/credentials
|
|
34
|
+
0. Click **Create credentials** > **OAuth client ID**:
|
|
35
|
+
|
|
36
|
+
> <img width="771" alt="Create credentials" src="https://user-images.githubusercontent.com/1402241/77865679-e89f3a00-722f-11ea-942d-5245091f22b8.png">
|
|
37
|
+
|
|
38
|
+
0. Select **Desktop app**, enter `Chrome Webstore Upload` and click **Create**
|
|
39
|
+
|
|
40
|
+
> <img width="568" alt="Create OAuth client ID" src="https://user-images.githubusercontent.com/1402241/163124196-c4bb4f26-9766-4766-bb81-3982875d3a84.png">
|
|
41
|
+
|
|
42
|
+
0. Save your ✅ `clientId` and ✅ `clientSecret`:
|
|
43
|
+
|
|
44
|
+
> <img width="554" alt="OAuth client created" src="https://user-images.githubusercontent.com/1402241/228934028-1ef55a41-cc92-4ecf-967a-1984a363c21d.png">
|
|
45
|
+
|
|
46
|
+
0. Visit https://console.cloud.google.com/apis/credentials/consent
|
|
47
|
+
0. Click **PUBLISH APP** and confirm
|
|
48
|
+
|
|
49
|
+
> <img width="771" alt="Publish app" src="https://user-images.githubusercontent.com/27696701/114265946-2da2a280-9a26-11eb-9567-c4e00f572500.png">
|
|
50
|
+
|
|
51
|
+
0. Run this CLI tool to generate the required `refreshToken`
|
|
52
|
+
```sh
|
|
53
|
+
npx chrome-webstore-upload-keys
|
|
54
|
+
```
|
|
55
|
+
or
|
|
56
|
+
```sh
|
|
57
|
+
bunx chrome-webstore-upload-keys
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
> <img width="771" alt="chrome-webstore-upload-keys demo" src="./demo.gif">
|
|
61
|
+
|
|
62
|
+
9001. Done. Now you should have ✅ `clientId`, ✅ `clientSecret` and ✅ `refreshToken`. You can use these for all your extensions, but don't share them!
|
|
63
|
+
|
|
64
|
+
## What the CLI tool does
|
|
65
|
+
|
|
66
|
+
1. Requests the two keys you have
|
|
67
|
+
2. Opens a local server to handle the OAuth redirect from Google's servers with an `approvalCode`
|
|
68
|
+
3. Uses Google's `oauth2` API to request a `refreshToken`
|