diff --git a/packages/axis-core/src/auth/client-provider.ts b/packages/axis-core/src/auth/client-provider.ts deleted file mode 100644 index 7eca23b3f..000000000 --- a/packages/axis-core/src/auth/client-provider.ts +++ /dev/null @@ -1,62 +0,0 @@ -import got, { Agents, Got } from 'got'; -import * as http from 'http'; -import * as https from 'https'; -import * as basic from './basic'; -import { parse } from './challenge'; -import * as digest from './digest'; - -export const clientProvider = (method: string, url: string, username: string, password: string, agent?: http.Agent | https.Agent): Got => { - return got.extend({ - agent: createAgent(agent), - hooks: { - afterResponse: [ - (res, retryWithMergedOptions) => { - if (res.statusCode !== 401) { - return res; - } - - const wwwAuthenticate = res.headers['www-authenticate']; - if (wwwAuthenticate === undefined) { - return res; - } - - const updatedOptions = { - headers: { - authorization: '', - }, - }; - - const challenge = parse(wwwAuthenticate); - switch (challenge.type) { - case basic.BASIC: - updatedOptions.headers.authorization = basic.createHeader(username, password, challenge); - break; - - case digest.DIGEST: - updatedOptions.headers.authorization = digest.createHeader( - method, - url, - username, - password, - challenge, - challenge.qop === 'auth' ? digest.createCnonce() : undefined - ); - break; - - default: - return res; - } - - return retryWithMergedOptions(updatedOptions); - }, - ], - }, - }); -}; - -const createAgent = (agent?: http.Agent | https.Agent): Agents => { - return { - http: agent instanceof http.Agent ? agent : undefined, - https: agent instanceof https.Agent ? agent : undefined, - }; -};