@acidemic/axios-digest-auth

中文文档
0.9.9发布于 2023/11/17MITCommonJS近 30 天下载 2106

axios-like http digest auth

原始使用文档
文档目录9 节
  1. Overview
  2. Installation
  3. Essential Usage
  4. API
  5. class AxiosDigestAuth
  6. new AxiosDigestAuth()
  7. request()
  8. interface AxiosDigestAuthOpts
  9. Usage in the Browser with Webpack and Typescript

axios-digest-auth

Overview

A library which implements HTTP digest authentication in a manner which should be familiar to any project which also uses Axios. Can be used in both Node.js and browser environments.

This library is not affiliated with the Axios project or its maintainers, other than its input/output data structures being identical to those Axios uses, and it relying on Axios.

This is fork of @mhoc/axios-digest-auth package

This improved version of the package adds support for the following:

  • returns 'opaque' value from the server as part of the response headers (see RFC 7616)
  • added generic for request data

Installation

$ npm i @acidemic/axios-digest-auth

Essential Usage

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

const digestAuth = new AxiosDigestAuth({
  username: "myDigestUsername",
  password: "myDigestPassword",
});

const MakeARequest = async () => {
  const response = await digestAuth.request({
    headers: { Accept: "application/json" },
    method: "GET",
    url: "https://cloud.mongodb.com/api/atlas/v1.0/groups",
  });
}

API

class AxiosDigestAuth

import AxiosDigestAuth from "@acidemic/axios-digest-auth";

Application-facing class which stores username/password state and executes requests.

new AxiosDigestAuth()

const options: AxiosDigestAuthOpts = {
  axios,
  password,
  username,
};
const axiosDigestAuthInst = new AxiosDigestAuth(options);
  • => AxiosDigestAuthOpts: input object (see below)

request()

import * as axios from "axios";
// you dont have to import this or add it to your package.json.
// just using it to outline where these types are coming from.

const ExecuteMyRequest = async () => {
  const requestOptions: axios.AxiosRequestConfig = {
    headers: { Accept: "application/json" },
    method: "GET",
    url: "https://cloud.mongodb.com/api/atlas/v1.0/groups",
  };
  const response: axios.AxiosResponse = await axiosDigestAuthInst.request(requestOptions);
};

Executes a request. The signature of this function is identical to Axios's own request method.

  • => axios.AxiosRequestConfig: refer to the Axios documentation for more information on this type.
  • <= axios.AxiosResponse: refer to the Axios documentation for more information on this type.

interface AxiosDigestAuthOpts

import { AxiosDigestAuthOpts } from "@acidemic/axios-digest-auth";
  • axios (axios.Axios | undefined): Optionally provide an axios object with which requests are made. If this is not provided, axios-digest-auth will create one for you by simply using the axios library default export, with no configuration.
  • password (string): the HTTP digest authentication password to use.
  • username (string): the HTTP digest authentication username to use.

Check out the documentation site for more information on usage.

Usage in the Browser with Webpack and Typescript

This module utilizes certain built-in Node.js modules. To use it in a browser, you'll need to include a polyfill for each of these modules.

Firstly, install all necessary modules by executing the following command in your terminal:

npm install crypto-browserify buffer stream-browserify url

Next, add a fallback in your webpack configuration file (typically named webpack.config.js):

module.exports = {
  //...
  resolve: {
    fallback: {
      "crypto": require.resolve("crypto-browserify"),
      "buffer": require.resolve("buffer/"),
      "stream": require.resolve("stream-browserify"),
      "url": require.resolve("url/")
    },
  },
};

版本与发布记录

@acidemic/axios-digest-auth 共发布 10 个版本,首次发布于 2023/11/16;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.9.9latest2023/11/172 年前
0.9.82023/11/172 年前
0.9.72023/11/172 年前
0.9.62023/11/172 年前
0.9.52023/11/172 年前
0.9.42023/11/172 年前

关于 @acidemic/axios-digest-auth 的常见问题

@acidemic/axios-digest-auth 是什么?

axios-like http digest auth

如何安装 @acidemic/axios-digest-auth?

在项目目录运行 npm install @acidemic/axios-digest-auth,或使用 pnpm add / yarn add / bun add。

@acidemic/axios-digest-auth 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/acidemic__axios-digest-auth 是否存在。

@acidemic/axios-digest-auth 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@acidemic/axios-digest-auth 可以商用吗?

@acidemic/axios-digest-auth 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@acidemic/axios-digest-auth 的下载量有多少?

根据 npm 官方下载统计,@acidemic/axios-digest-auth 在 2026/10/05 – 2026/11/03 这 30 天内被下载 2,106 次,日均约 70 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@acidemic/axios-digest-auth 还在维护吗?

最新版本 0.9.9 发布于 2023/11/17(2 年前);至今共发布 10 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/11/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。