npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@acidemic/axios-digest-auth

v0.9.9

Published

axios-like http digest auth

Downloads

21

Readme

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.

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/")
    },
  },
};