Skip to content

Commit 2684ec9

Browse files
committed
Port package to delete a token from kgryte/github-delete-token
1 parent f68fb41 commit 2684ec9

29 files changed

+2715
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,290 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2021 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# Delete Token
22+
23+
> [Delete][github-delete-token] a Github OAuth access [token][github-token].
24+
25+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
26+
27+
<section class="intro">
28+
29+
</section>
30+
31+
<!-- /.intro -->
32+
33+
<!-- Package usage documentation. -->
34+
35+
<section class="usage">
36+
37+
## Usage
38+
39+
```javascript
40+
var deleteToken = require( '@stdlib/_tools/github/delete-token' );
41+
```
42+
43+
<a name="delete-token"></a>
44+
45+
#### deleteToken( id, options, clbk )
46+
47+
[Deletes][github-delete-token] a Github OAuth access [token][github-token].
48+
49+
<!-- run-disable -->
50+
51+
```javascript
52+
var tokenID = 1;
53+
54+
var opts = {
55+
'username': 'beep',
56+
'password': 'boop'
57+
};
58+
59+
deleteToken( tokenID, opts, clbk );
60+
61+
function clbk( error, info ) {
62+
// Check for rate limit information...
63+
if ( info ) {
64+
console.error( 'Limit: %d', info.limit );
65+
console.error( 'Remaining: %d', info.remaining );
66+
console.error( 'Reset: %s', (new Date( info.reset*1000 )).toISOString() );
67+
}
68+
if ( error ) {
69+
throw new Error( error.message );
70+
}
71+
console.log( 'Success!' );
72+
}
73+
```
74+
75+
The `function` accepts the following `options`:
76+
77+
- **username**: Github username (_required_).
78+
- **password**: Github password (_required_).
79+
- **otp**: Github one-time password (2-factor authentication).
80+
- **useragent**: [user agent][github-user-agent] `string`.
81+
82+
The `function` **only** supports basic authentication using a `username` and `password`. To [authenticate][github-oauth2] with Github, set the `username` and `password` options.
83+
84+
<!-- run-disable -->
85+
86+
```javascript
87+
var opts = {
88+
'username': 'beep',
89+
'password': 'boop'
90+
};
91+
92+
deleteToken( tokenID, opts, clbk );
93+
```
94+
95+
To specify a [user agent][github-user-agent], set the `useragent` option.
96+
97+
<!-- run-disable -->
98+
99+
```javascript
100+
var opts = {
101+
'username': 'beep',
102+
'password': 'boop',
103+
'useragent': 'hello-github!'
104+
};
105+
106+
deleteToken( tokenID, opts, clbk );
107+
```
108+
109+
If a user has [two-factor authentication][github-two-factor] enabled, set the `otp` (one-time password) option.
110+
111+
<!-- run-disable -->
112+
113+
```javascript
114+
var opts = {
115+
'username': 'beep',
116+
'password': 'boop',
117+
'otp': '1234'
118+
};
119+
120+
deleteToken( tokenID, opts, clbk );
121+
```
122+
123+
</section>
124+
125+
<!-- /.usage -->
126+
127+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
128+
129+
<section class="notes">
130+
131+
## Notes
132+
133+
- [Rate limit][github-rate-limit] information includes the following:
134+
- **limit**: maximum number of requests a consumer is permitted to make per hour.
135+
- **remaining**: number of remaining requests.
136+
- **reset**: time at which the current [rate limit][github-rate-limit] window resets in [UTC seconds][unix-time].
137+
138+
</section>
139+
140+
<!-- /.notes -->
141+
142+
<!-- Package usage examples. -->
143+
144+
<section class="examples">
145+
146+
## Examples
147+
148+
```javascript
149+
var deleteToken = require( '@stdlib/_tools/github/delete-token' );
150+
151+
var tokenID = 1;
152+
153+
var opts = {
154+
'username': '<username>',
155+
'password': '<password>',
156+
'otp': '<otp>',
157+
'useragent': 'beep-boop-bop'
158+
};
159+
160+
deleteToken( tokenID, opts, clbk );
161+
162+
function clbk( error, info ) {
163+
if ( error ) {
164+
if ( error instanceof Error ) {
165+
throw error;
166+
}
167+
console.error( error.message );
168+
} else {
169+
console.log( 'Success!' );
170+
}
171+
}
172+
```
173+
174+
</section>
175+
176+
<!-- /.examples -->
177+
178+
<!-- Section for describing a command-line interface. -->
179+
180+
* * *
181+
182+
<section class="cli">
183+
184+
## CLI
185+
186+
<!-- CLI usage documentation. -->
187+
188+
<section class="usage">
189+
190+
### Usage
191+
192+
```bash
193+
Usage: ghdeletetoken [options] token_id
194+
195+
Options:
196+
197+
-h, --help Print this message.
198+
-V, --version Print the package version.
199+
--username username Github username.
200+
--password password Github password.
201+
--otp password Github one-time password.
202+
-ua, --useragent ua User agent.
203+
```
204+
205+
</section>
206+
207+
<!-- /.usage -->
208+
209+
<!-- CLI usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
210+
211+
<section class="notes">
212+
213+
### Notes
214+
215+
- If a `username` is **not** provided, the implementation will attempt to infer a username by executing
216+
217+
<!-- run-disable -->
218+
219+
```bash
220+
git config user.name
221+
```
222+
223+
in the current working directory.
224+
225+
- If a `password` is **not** provided, the user will be prompted to provide a `password`.
226+
227+
- In addition to the `username` and `password` options, a `username` and `password` may also be specified by `GITHUB_USERNAME` and `GITHUB_PASSWORD` environment variables. The command-line options **always** take precedence.
228+
229+
- [Rate limit][github-rate-limit] information is written to `stderr`.
230+
231+
</section>
232+
233+
<!-- /.notes -->
234+
235+
<!-- CLI usage examples. -->
236+
237+
<section class="examples">
238+
239+
### Examples
240+
241+
Setting a username and password using the command-line options:
242+
243+
<!-- run-disable -->
244+
245+
```bash
246+
$ DEBUG=* ghdeletetoken --username <username> --password <password> 1234
247+
# => 'Deleted token 1234.'
248+
```
249+
250+
Setting a username and password using environment variables:
251+
252+
<!-- run-disable -->
253+
254+
```bash
255+
$ DEBUG=* GITHUB_USERNAME=<username> GITHUB_PASSWORD=<password> ghdeletetoken 1234
256+
# => 'Deleted token 1234.'
257+
```
258+
259+
</section>
260+
261+
<!-- /.examples -->
262+
263+
</section>
264+
265+
<!-- /.cli -->
266+
267+
<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
268+
269+
<section class="references">
270+
271+
</section>
272+
273+
<!-- /.references -->
274+
275+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
276+
277+
<section class="links">
278+
279+
[unix-time]: http://en.wikipedia.org/wiki/Unix_time
280+
281+
[github-token]: https://github.com/settings/tokens/new
282+
[github-oauth2]: https://developer.github.com/v3/#oauth2-token-sent-in-a-header
283+
[github-user-agent]: https://developer.github.com/v3/#user-agent-required
284+
[github-rate-limit]: https://developer.github.com/v3/rate_limit/
285+
[github-delete-token]: https://developer.github.com/v3/oauth_authorizations/#delete-an-authorization
286+
[github-two-factor]: https://help.github.com/articles/about-two-factor-authentication/
287+
288+
</section>
289+
290+
<!-- /.links -->

0 commit comments

Comments
 (0)