Skip to content

Commit ad4f149

Browse files
copperwallgr2m
authored andcommitted
breaking: remove "netrc" authentication type (#640)
BREAKING CHANGE: Authentication with `"netrc"` is no longer supported: ```js github.authenticate({ type: "netrc" }) ``` Instead, use the [netrc](https://www.npmjs.com/package/netrc) package directly and pass username/password to `"basic"` authentication ```js const netrc = require('netrc') const myNetrc = netrc() github.authenticate({ type: 'basic', username: myNetrc['api.github.com'].login, password: myNetrc['api.github.com'].password }) ```
1 parent 68cf60e commit ad4f149

File tree

3 files changed

+3
-18
lines changed

3 files changed

+3
-18
lines changed

README.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,6 @@ github.authenticate({
128128
type: 'integration',
129129
token: 'jwt'
130130
})
131-
132-
// ~/.netrc
133-
github.authenticate({
134-
type: 'netrc'
135-
})
136131
```
137132

138133
Note: `authenticate` is synchronous because it only stores the

lib/index.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ var fs = require('fs')
44

55
var HttpsProxyAgent = require('https-proxy-agent')
66
var mime = require('mime')
7-
var netrc = require('netrc')
87
var toCamelCase = require('lodash/camelCase')
98

109
var error = require('./error')
@@ -349,8 +348,8 @@ var Client = module.exports = function (config) {
349348
this.auth = false
350349
return
351350
}
352-
if (!options.type || 'basic|oauth|client|token|integration|netrc'.indexOf(options.type) === -1) {
353-
throw new Error("Invalid authentication type, must be 'basic', 'integration', 'oauth', 'client' or 'netrc'")
351+
if (!options.type || 'basic|oauth|client|token|integration'.indexOf(options.type) === -1) {
352+
throw new Error("Invalid authentication type, must be 'basic', 'integration', 'oauth', or 'client'")
354353
}
355354
if (options.type === 'basic' && (!options.username || !options.password)) {
356355
throw new Error('Basic authentication requires both a username and password to be set')
@@ -720,14 +719,6 @@ var Client = module.exports = function (config) {
720719
basic = Buffer.from(this.auth.username + ':' + this.auth.password, 'ascii').toString('base64')
721720
headers['Authorization'] = 'Basic ' + basic
722721
break
723-
case 'netrc':
724-
var auth = netrc()[host]
725-
if (!auth) {
726-
throw new Error("~/.netrc authentication type chosen but no credentials found for '" + host + "'")
727-
}
728-
basic = Buffer.from(auth.login + ':' + auth.password, 'ascii').toString('base64')
729-
headers['Authorization'] = 'Basic ' + basic
730-
break
731722
default:
732723
break
733724
}

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030
"follow-redirects": "1.2.6",
3131
"https-proxy-agent": "^2.1.0",
3232
"lodash": "^4.17.4",
33-
"mime": "^2.0.3",
34-
"netrc": "^0.1.4"
33+
"mime": "^2.0.3"
3534
},
3635
"devDependencies": {
3736
"@octokit/fixtures": "^5.4.0",

0 commit comments

Comments
 (0)