Welcome to mirror list, hosted at ThFree Co, Russian Federation.

authify.js « lib « npm-registry-client « node_modules « npm « deps - github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4d1a4dd4aba7f84508f403e9a17f74e5d65669da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
module.exports = authify

function authify (authed, parsed, headers, credentials) {
  if (credentials && credentials.token) {
    this.log.verbose("request", "using bearer token for auth")
    headers.authorization = "Bearer " + credentials.token

    return null
  }

  if (authed) {
    if (credentials && credentials.username && credentials.password) {
      var username = encodeURIComponent(credentials.username)
      var password = encodeURIComponent(credentials.password)
      parsed.auth = username + ":" + password
    }
    else {
      return new Error(
        "This request requires auth credentials. Run `npm login` and repeat the request."
      )
    }
  }
}