node-modules / urllib

Request HTTP(s) URLs in a complex world.
MIT License
726 stars 117 forks source link

Digest Auth fails when server provides multiple algorithms #420

Closed ghost closed 1 year ago

ghost commented 1 year ago

src/HttpClient.ts:425

      if (response.statusCode === 401 && response.headers['www-authenticate'] &&
          !requestOptions.headers.authorization && args.digestAuth) {
        const authenticate = response.headers['www-authenticate'];
        // Error is here. Authenticate is Array<string> when server provides multiple methods
       // 
        if (authenticate.startsWith('Digest ')) {
          debug('Request#%d %s: got digest auth header WWW-Authenticate: %s', requestId, requestUrl.href, authenticate);
          requestOptions.headers.authorization = digestAuthHeader(requestOptions.method!,
            `${requestUrl.pathname}${requestUrl.search}`, authenticate, args.digestAuth);
          debug('Request#%d %s: auth with digest header: %s', requestId, url, requestOptions.headers.authorization);
          if (response.headers['set-cookie']) {
            // FIXME: merge exists cookie header
            requestOptions.headers.cookie = response.headers['set-cookie'].join(';');
          }
          response = await undiciRequest(requestUrl, requestOptions);
        }
      }

error:

            if (authenticate.startsWith('Digest ')) {
                             ^

TypeError: authenticate.startsWith is not a function