Skip to content

Ambiguity on basic auth and authorization header between instance based request and plan requests #221

Open
@karloluis

Description

@karloluis

Describe the bug
The ambiguity of the docs between instance based requests and plan requests can cause confusion with regards to (basic) auth property and the Authorization header. The docs do not differentiate between request configurations and instanced based requests.

// auth indicates that HTTP Basic auth should be used, and supplies credentials.
// This will set an Authorization header, overwriting any existing
// Authorization custom headers you have set using headers.

Is it expected for Requests made using a defined instance to no be able to override the authorization header directly if the instance has a basic auth configured?

To Reproduce
Steps to reproduce the behavior:

// Plain axios request documented to prioritized `auth` field
const getWithAuthAndAuthHeader = axios.get(
  "http://example.com/",
  {
    auth: {
      username: "username",
      password: "secure password"
    },
    headers: { Authorization: "OVERWRITTEN AUTH HEADER"}
  }
)

// An axios instance with basic auth pre-configured
const instance = axios.create({
  baseURL: "http://example.com",
  auth: {
    username: "username",
    password: "secure password"
  },
})

// Uses the instance and does not warn that Authrization header will be ignored
const getWithAuthHeaderOverride = instance.get("/", {
  headers: {
    Authorization: "AMBIGUOUSLY OVERWRITTEN AUTH HEADER"
  }
})

// Uses the instance and circumvents the configured basic auth configuration
const getWithAuthHeaderOverride = instance.get("/", {
  auth: null, // explicitly bypass basic auth
  headers: {
    Authorization: "OVERWRITTEN AUTH HEADER"
  }
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions