1 var assert = require("assert")
3 var toNerfDart = require("./nerf-dart.js")
5 module.exports = getCredentialsByURI
7 function getCredentialsByURI (uri) {
8 assert(uri && typeof uri === "string", "registry URL is required")
9 var nerfed = toNerfDart(uri)
10 var defnerf = toNerfDart(this.get("registry"))
12 // hidden class micro-optimization
20 alwaysAuth : undefined
23 // used to override scope matching for tokens as well as legacy auth
24 if (this.get(nerfed + ':always-auth') !== undefined) {
25 var val = this.get(nerfed + ':always-auth')
26 c.alwaysAuth = val === 'false' ? false : !!val
27 } else if (this.get('always-auth') !== undefined) {
28 c.alwaysAuth = this.get('always-auth')
31 if (this.get(nerfed + ':_authToken')) {
32 c.token = this.get(nerfed + ':_authToken')
33 // the bearer token is enough, don't confuse things
37 // Handle the old-style _auth=<base64> style for the default
40 // XXX(isaacs): Remove when npm 1.4 is no longer relevant
41 var authDef = this.get("_auth")
42 var userDef = this.get("username")
43 var passDef = this.get("_password")
44 if (authDef && !(userDef && passDef)) {
45 authDef = new Buffer(authDef, "base64").toString()
46 authDef = authDef.split(":")
47 userDef = authDef.shift()
48 passDef = authDef.join(":")
51 if (this.get(nerfed + ":_password")) {
52 c.password = new Buffer(this.get(nerfed + ":_password"), "base64").toString("utf8")
53 } else if (nerfed === defnerf && passDef) {
57 if (this.get(nerfed + ":username")) {
58 c.username = this.get(nerfed + ":username")
59 } else if (nerfed === defnerf && userDef) {
63 if (this.get(nerfed + ":email")) {
64 c.email = this.get(nerfed + ":email")
65 } else if (this.get("email")) {
66 c.email = this.get("email")
69 if (c.username && c.password) {
70 c.auth = new Buffer(c.username + ":" + c.password).toString("base64")