mhoc / axios-digest-auth

Axios-like HTTP Digest Auth
https://axios-digest-auth.mhoc.co
The Unlicense
12 stars 20 forks source link

Still getting 401 unauthorized #2

Closed Ali-Nass closed 3 years ago

Ali-Nass commented 3 years ago

I'm trying to apply a simple scenario like the following:

import AxiosDigestAuth from '@mhoc/axios-digest-auth';

const digestAuth = new AxiosDigestAuth({
  password: 'pass',
  username: 'user',
});

const response = await digestAuth.request({
  headers: { Accept: 'application/json' },
  method: 'POST',
  data,
  url,
});

Is there anything I'm missing to add?

I'm getting the following in the logs:

"headers":{"Accept":"application/json","Content-Type":"application/x-www-form-urlencoded","authorization":"Digest username=\"user\",realm=\"Something\",nonce=\"F0WPyO/ckHwF7KbJIXQ4yWxhav/0jw9v\",uri=\"uri",qop=\"auth\",algorithm=\"MD5\",response=\"8f84c8e1cdcf177bf74304b3d52675aa\",nc=\"00000001\",cnonce=\"17ff0f091b3949da7911654890914a55a380f2ff57a1ca13\"","User-Agent":"axios/0.21.1","Content-Length":77,"x-datadog-trace-id":"385142050296865726","x-datadog-parent-id":"2471136348259650736","x-datadog-sampled":"1","x-datadog-sampling-priority":"1"},"transformRequest":[null],"transformResponse":[null],"timeout":0,"xsrfCookieName":"XSRF-TOKEN","xsrfHeaderName":"X-XSRF-TOKEN","maxContentLength":-1,"maxBodyLength":-1}}

Ali-Nass commented 3 years ago

I was able to make it work by configuring my own axios instance with keep connection alive

  const httpsAgent = new https.Agent({ keepAlive: true });
  const httpAgent = new https.Agent({ keepAlive: true });
  const axiosInstance = axios.create({
    httpsAgent,
    httpAgent,
  });

and then pass this instance to the library

  const digestAuth = new AxiosDigestAuth({
    username,
    password,
    axios: axiosInstance,
  });

and now it's working like a charm!