This repository has been archived by the owner on Aug 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make it do something useful on both bearer-based and basic-based authed clients.
- Loading branch information
Showing
4 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
npm-logout(1) -- Log out of the registry | ||
======================================== | ||
|
||
## SYNOPSIS | ||
|
||
npm logout [--registry=url] [--scope=@orgname] | ||
|
||
## DESCRIPTION | ||
|
||
When logged into a registry that supports token-based authentication, tell the | ||
server to end this token's session. This will invalidate the token everywhere | ||
you're using it, not just for the current environment. | ||
|
||
When logged into a legacy registry that uses username and password authentication, this will | ||
clear the credentials in your user configuration. In this case, it will _only_ affect | ||
the current environment. | ||
|
||
If `--scope` is provided, this will find the credentials for the registry | ||
connected to that scope, if set. | ||
|
||
## CONFIGURATION | ||
|
||
### registry | ||
|
||
Default: http://registry.npmjs.org/ | ||
|
||
The base URL of the npm package registry. If `scope` is also specified, | ||
it takes precedence. | ||
|
||
### scope | ||
|
||
Default: none | ||
|
||
If specified, the user and login credentials given will be associated | ||
with the specified scope. See `npm-scope(7)`. You can use both at the same time, | ||
e.g. | ||
|
||
npm adduser --registry=http://myregistry.example.com --scope=@myco | ||
|
||
This will set a registry for the given scope and login or create a user for | ||
that registry at the same time. | ||
|
||
## SEE ALSO | ||
|
||
* npm-adduser(1) | ||
* npm-registry(7) | ||
* npm-config(1) | ||
* npm-config(7) | ||
* npmrc(5) | ||
* npm-whoami(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module.exports = logout | ||
|
||
var dezalgo = require("dezalgo") | ||
var log = require("npmlog") | ||
|
||
var npm = require("./npm.js") | ||
var mapToRegistry = require("./utils/map-to-registry.js") | ||
|
||
logout.usage = "npm logout [--registry] [--scope]" | ||
|
||
function logout (args, cb) { | ||
npm.spinner.start() | ||
cb = dezalgo(cb) | ||
|
||
mapToRegistry("/", npm.config, function (err, uri, auth, normalized) { | ||
if (err) return cb(err) | ||
|
||
if (auth.token) { | ||
log.verbose("logout", "clearing session token for", normalized) | ||
npm.registry.logout(normalized, { auth: auth }, function (err) { | ||
if (err) return cb(err) | ||
|
||
npm.config.clearCredentialsByURI(normalized) | ||
npm.spinner.stop() | ||
npm.config.save("user", cb) | ||
}) | ||
} | ||
else if (auth.username || auth.password) { | ||
log.verbose("logout", "clearing user credentials for", normalized) | ||
npm.config.clearCredentialsByURI(normalized) | ||
npm.spinner.stop() | ||
npm.config.save("user", cb) | ||
} | ||
else { | ||
cb(new Error( | ||
"Not logged in to", normalized + ",", "so can't log out." | ||
)) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,6 +110,7 @@ var commandCache = {} | |
, "stars" | ||
, "tag" | ||
, "adduser" | ||
, "logout" | ||
, "unpublish" | ||
, "owner" | ||
, "access" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
var fs = require("fs") | ||
var path = require("path") | ||
|
||
var mkdirp = require("mkdirp") | ||
var mr = require("npm-registry-mock") | ||
var rimraf = require("rimraf") | ||
var test = require("tap").test | ||
|
||
var common = require("../common-tap.js") | ||
|
||
var pkg = path.resolve(__dirname, "logout") | ||
var outfile = path.join(pkg, "_npmrc") | ||
var opts = { cwd: pkg } | ||
|
||
var contents = function () {/* | ||
foo=boo | ||
//localhost:1337/:_authToken=glarb | ||
*/}.toString().split("\n").slice(1, -1).join("\n") | ||
|
||
function mocks (server) { | ||
server.delete("/-/user/token/glarb") | ||
.reply(200, {}) | ||
} | ||
|
||
test("setup", function (t) { | ||
cleanup() | ||
setup() | ||
t.end() | ||
}) | ||
|
||
test("npm logout", function (t) { | ||
mr({ port: common.port, plugin: mocks }, function (err, s) { | ||
if (err) throw err | ||
|
||
common.npm( | ||
[ | ||
"logout", | ||
"--registry", common.registry, | ||
"--loglevel", "silent", | ||
"--userconfig", outfile | ||
], | ||
opts, | ||
function (err, code) { | ||
t.ifError(err, "no error output") | ||
t.notOk(code, "exited OK") | ||
|
||
var config = fs.readFileSync(outfile, "utf8") | ||
t.equal(config, "foo=boo\n", "creds gone") | ||
s.close() | ||
t.end() | ||
}) | ||
}) | ||
}) | ||
|
||
test("cleanup", function (t) { | ||
cleanup() | ||
t.end() | ||
}) | ||
|
||
function setup () { | ||
mkdirp.sync(pkg) | ||
fs.writeFileSync(outfile, contents) | ||
} | ||
|
||
function cleanup () { | ||
rimraf.sync(pkg) | ||
} |