{"id":16718941,"url":"https://github.com/kgryte/github-create-token","last_synced_at":"2025-04-10T08:54:07.544Z","repository":{"id":57251256,"uuid":"53176346","full_name":"kgryte/github-create-token","owner":"kgryte","description":"Create a Github OAuth access token.","archived":false,"fork":false,"pushed_at":"2017-02-01T21:12:37.000Z","size":41,"stargazers_count":6,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-08T08:21:24.131Z","etag":null,"topics":["api","authenticate","authentication","authorization","authorize","github","oauth","token"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kgryte.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-03-05T01:28:35.000Z","updated_at":"2023-03-10T11:55:47.000Z","dependencies_parsed_at":"2022-08-24T17:01:21.983Z","dependency_job_id":null,"html_url":"https://github.com/kgryte/github-create-token","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kgryte%2Fgithub-create-token","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kgryte%2Fgithub-create-token/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kgryte%2Fgithub-create-token/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kgryte%2Fgithub-create-token/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kgryte","download_url":"https://codeload.github.com/kgryte/github-create-token/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248190407,"owners_count":21062277,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","authenticate","authentication","authorization","authorize","github","oauth","token"],"created_at":"2024-10-12T21:39:25.594Z","updated_at":"2025-04-10T08:54:07.521Z","avatar_url":"https://github.com/kgryte.png","language":"JavaScript","readme":"Create Token\n===\n[![NPM version][npm-image]][npm-url] [![Build Status][build-image]][build-url] [![Coverage Status][coverage-image]][coverage-url] [![Dependencies][dependencies-image]][dependencies-url]\n\n\u003e [Create][github-create-token] a Github OAuth access [token][github-token].\n\n\n## Installation\n\n``` bash\n$ npm install github-create-token\n```\n\n\n## Usage\n\n``` javascript\nvar createToken = require( 'github-create-token' );\n```\n\n\u003ca name=\"create-token\"\u003e\u003c/a\u003e\n#### createToken( options, clbk )\n\n[Creates][github-create-token] a Github OAuth access [token][github-token].\n\n``` javascript\nvar opts = {\n\t'username': 'beep',\n\t'password': 'boop',\n\t'scopes': [ 'public_repo', 'read:org' ],\n\t'note': 'beep'\n};\n\ncreateToken( opts, clbk );\n\nfunction clbk( error, results, info ) {\n\t// Check for rate limit information...\n\tif ( info ) {\n\t\tconsole.error( 'Limit: %d', info.limit );\n\t\tconsole.error( 'Remaining: %d', info.remaining );\n\t\tconsole.error( 'Reset: %s', (new Date( info.reset*1000 )).toISOString() );\n\t}\n\tif ( error ) {\n\t\tthrow new Error( error.message );\n\t}\n\tconsole.log( JSON.stringify( results ) );\n\t/* returns\n\t\t{\n\t\t\t\"id\": 1,\n\t\t\t\"url\":\"https://api.github.com/authorizations/1\",\n\t\t\t\"app\": {\n\t\t\t\t\"name\":\"beep\",\n\t\t\t\t\"url\":\"https://developer.github.com/v3/oauth_authorizations/\",\n\t\t\t\t\"client_id\":\"00000000000000000000\"\n\t\t\t},\n\t\t\t\"token\": \"abcdefgh12345678\",\n\t\t\t\"hashed_token\": \"25f94a2a5c7fbaf499c665bc73d67c1c87e496da8985131633ee0a95819db2e8\",\n\t\t\t\"token_last_eight\": \"12345678\",\n\t\t\t\"note\": \"beep\",\n\t\t\t\"note_url\": null,\n\t\t\t\"created_at\": \"2016-03-05T06:34:01Z\",\n\t\t\t\"updated_at\": \"2016-03-05T06:34:01Z\",\n\t\t\t\"scopes\": [\n\t\t\t\t\"public_repo\",\n\t\t\t\t\"read:org\"\n\t\t\t],\n\t\t\t\"fingerprint\": null\n\t\t}\n\t*/\n}\n```\n\nThe `function` accepts the following `options`:\n*\t__username__: Github username (*required*).\n* \t__password__: Github password (*required*).\n*\t__scopes__: list of [scopes][github-scopes] (*required*).\n*\t__note__: a note as to the purpose of the [token][github-token] (*required*).\n*\t__otp__: Github one-time password (2-factor authentication).\n*\t__note_url__: an app URL if authorizing an application.\n*\t__client_id__: a `20` character OAuth app client key for which to create the [token][github-token].\n*\t__client_secret__: a `40` character OAuth app client secret for which to create the [token][github-token].\n*\t__fingerprint__: a unique `string` to distinguish a token from others created for the same client id and user.\n*\t__useragent__: [user agent][github-user-agent] `string`.\n\nThe `function` __only__ supports basic authentication using a `username` and `password`. To [authenticate][github-oauth2] with Github, set the `username` and `password` options.\n\n``` javascript\nvar opts = {\n\t'username': 'beep',\n\t'password': 'boop',\n\t'scopes': [ 'public_repo' ],\n\t'note': 'for my beepboop app'\n};\n\ncreateToken( opts, clbk );\n```\n\nTo specify a [user agent][github-user-agent], set the `useragent` option.\n\n``` javascript\nvar opts = {\n\t'username': 'beep',\n\t'password': 'boop',\n\t'scopes': [ 'public_repo' ],\n\t'note': 'for my beepboop app',\n\t'useragent': 'hello-github!'\n};\n\ncreateToken( opts, clbk );\n```\n\nIf a user has [two-factor authentication][github-two-factor] enabled, set the `otp` (one-time password) option.\n\n``` javascript\nvar opts = {\n\t'username': 'beep',\n\t'password': 'boop',\n\t'otp': '1234',\n\t'scopes': [ 'public_repo' ],\n\t'note': 'for my beepboop app'\n};\n\ncreateToken( opts, clbk );\n```\n\n\n## Notes\n\n*\t[Rate limit][github-rate-limit] information includes the following:\n\t-\t__limit__: maximum number of requests a consumer is permitted to make per hour.\n\t-\t__remaining__: number of remaining requests.\n\t-\t__reset__: time at which the current [rate limit][github-rate-limit] window resets in [UTC seconds][unix-time].\n\n\n---\n## Examples\n\n``` javascript\nvar createToken = require( 'github-create-token' );\n\nvar opts = {\n\t'username': '\u003cusername\u003e',\n\t'password': '\u003cpassword\u003e',\n\t'otp': '\u003cotp\u003e',\n\t'scopes': [ 'public_repo' ],\n\t'note': 'for my beepboop app',\n\t'useragent': 'beep-boop-bop'\n};\n\ncreateToken( opts, clbk );\n\nfunction clbk( error, results, info ) {\n\tif ( info ) {\n\t\tconsole.error( info );\n\t}\n\tif ( error ) {\n\t\tthrow new Error( error.message );\n\t}\n\tconsole.log( results );\n}\n```\n\nTo run the example code from the top-level application directory,\n\n``` bash\n$ node ./examples/index.js\n```\n\n\n---\n## CLI\n\n### Installation\n\nTo use the module as a general utility, install the module globally\n\n``` bash\n$ npm install -g github-create-token\n```\n\n\n### Usage\n\n``` bash\nUsage: ghcreatetoken [options]\n\nOptions:\n\n  -h,  --help                      Print this message.\n  -V,  --version                   Print the package version.\n       --lscopes                   List all possible scopes.\n       --username username         Github username.\n       --password password         Github password.\n       --otp password              Github one-time password.\n  -ua, --useragent ua              User agent.\n       --scopes scope1,scope2,...  List of scopes.\n       --note note                 Token note.\n       --note_url url              Application URL.\n       --client_id id              Client id.\n       --client_secret secret      Client secret.\n       --fingerprint fingerprint   Unique token identifier.\n```\n\n\n### Notes\n\n*\tIf a `username` is __not__ provided, the implementation will attempt to infer a username by executing\n\n\t```\n\tgit config user.name\n\t```\n\t\n\tin the current working directory.\n*\tIf a `password` is __not__ provided, the user will be prompted to provide a `password`.\n*\tIn 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.\n*\t[Token][github-token] information is written to `stdout`.\n*\t[Rate limit][github-rate-limit] information is written to `stderr`.\n\n\n### Examples\n\nSetting a username and password using the command-line options:\n\n``` bash\n$ DEBUG=* ghcreatetoken --username \u003cusername\u003e --password \u003cpassword\u003e --scopes=read_org,repo_status --note 'for my beepboop app'\n# =\u003e '{...}'\n```\n\nSetting a username and password using environment variables:\n\n``` bash\n$ DEBUG=* GITHUB_USERNAME=\u003cusername\u003e GITHUB_PASSWORD=\u003cpassword\u003e ghcreatetoken --scopes=read_org,repo_status --note 'for my beepboop app'\n# =\u003e '{...}'\n```\n\nFor local installations, modify the command to point to the local installation directory; e.g., \n\n``` bash\n$ DEBUG=* ./node_modules/.bin/ghcreatetoken --scopes=read_org,repo_status --note 'for my beepboop app'\n# =\u003e '{...}'\n```\n\nOr, if you have cloned this repository and run `npm install`, modify the command to point to the executable; e.g., \n\n``` bash\n$ DEBUG=* node ./bin/cli --scopes=read_org,repo_status --note 'for my beepboop app'\n# =\u003e '{...}'\n```\n\n\n---\n## Tests\n\n### Unit\n\nThis repository uses [tape][tape] for unit tests. To run the tests, execute the following command in the top-level application directory:\n\n``` bash\n$ make test\n```\n\nAll new feature development should have corresponding unit tests to validate correct functionality.\n\n\n### Test Coverage\n\nThis repository uses [Istanbul][istanbul] as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:\n\n``` bash\n$ make test-cov\n```\n\nIstanbul creates a `./reports/coverage` directory. To access an HTML version of the report,\n\n``` bash\n$ make view-cov\n```\n\n\n### Browser Support\n\nThis repository uses [Testling][testling] for browser testing. To run the tests in a (headless) local web browser, execute the following command in the top-level application directory:\n\n``` bash\n$ make test-browsers\n```\n\nTo view the tests in a local web browser,\n\n``` bash\n$ make view-browser-tests\n```\n\n\u003c!-- [![browser support][browsers-image]][browsers-url] --\u003e\n\n\n---\n## License\n\n[MIT license](http://opensource.org/licenses/MIT).\n\n\n## Copyright\n\nCopyright \u0026copy; 2016. Athan Reines.\n\n\n[npm-image]: http://img.shields.io/npm/v/github-create-token.svg\n[npm-url]: https://npmjs.org/package/github-create-token\n\n[build-image]: http://img.shields.io/travis/kgryte/github-create-token/master.svg\n[build-url]: https://travis-ci.org/kgryte/github-create-token\n\n[coverage-image]: https://img.shields.io/codecov/c/github/kgryte/github-create-token/master.svg\n[coverage-url]: https://codecov.io/github/kgryte/github-create-token?branch=master\n\n[dependencies-image]: http://img.shields.io/david/kgryte/github-create-token.svg\n[dependencies-url]: https://david-dm.org/kgryte/github-create-token\n\n[dev-dependencies-image]: http://img.shields.io/david/dev/kgryte/github-create-token.svg\n[dev-dependencies-url]: https://david-dm.org/dev/kgryte/github-create-token\n\n[github-issues-image]: http://img.shields.io/github/issues/kgryte/github-create-token.svg\n[github-issues-url]: https://github.com/kgryte/github-create-token/issues\n\n[tape]: https://github.com/substack/tape\n[istanbul]: https://github.com/gotwarlost/istanbul\n[testling]: https://ci.testling.com\n\n[unix-time]: http://en.wikipedia.org/wiki/Unix_time\n\n[github-api]: https://developer.github.com/v3/\n[github-token]: https://github.com/settings/tokens/new\n[github-oauth2]: https://developer.github.com/v3/#oauth2-token-sent-in-a-header\n[github-user-agent]: https://developer.github.com/v3/#user-agent-required\n[github-rate-limit]: https://developer.github.com/v3/rate_limit/\n[github-create-token]: https://developer.github.com/v3/oauth_authorizations/#create-a-new-authorization\n[github-two-factor]: https://help.github.com/articles/about-two-factor-authentication/\n[github-scopes]: https://developer.github.com/v3/oauth/#scopes\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkgryte%2Fgithub-create-token","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkgryte%2Fgithub-create-token","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkgryte%2Fgithub-create-token/lists"}