esp8266 / esp8266/Arduino

HTTPClient library only allows Basic authorization

Open
#7,688 6 comments 1 reaction 0 assignees View on GitHub
waiting for feedback
Dominant language
C++
Stars
16.7k
Forks
13.1k
PR merge metrics
No merged PRs in 30d

Description

### Basic Infos

- [x] This issue complies with the [issue POLICY doc](https://github.com/esp8266/Arduino/blob/master/POLICY.md).
- [x] I have read the documentation at [readthedocs](https://arduino-esp8266.readthedocs.io/en/latest) and the issue is not addressed there.
- [x] I have tested that the issue is present in current master branch (aka latest git).
- [x] I have searched the issue tracker for a similar issue.
- [x] If there is a stack dump, I have decoded it.
- [x] I have filled out all fields below.

#### Platform

- Hardware: ESP-12F
- Core Version: 2.7.4
- Development Env: Arduino IDE
- Operating System: MacOS

### Settings in IDE

- Module: Wemos D1 R2
- Flash Mode: qio
- Flash Size: 4MB
- lwip Variant: v2 Lower Memory
- Reset Method: ck
- Flash Frequency: 40Mhz
- CPU Frequency: 80Mhz
- Upload Using: SERIAL
- Upload Speed: 921600

### Problem Description

After checking the source code of the library, it seems that the only way to set the `Authorization` header is through the use of either of the 2 `setAuthorization` methods (adding the header manually through the `addHeader` method does nothing for this header).
However, both of these methods internally set a base64 encoded field, which is then used as `Basic` type authentication.

As far as I can see, there is no way to set a `Bearer` token to authenticate requests.

### [MCVE](https://stackoverflow.com/help/mcve) Sketch

```cpp

#include
#include

const char* ssid = "ssid";
const char* password = "pass";
HTTPClient client;

void setup() {
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);

// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
}

void loop() {
client.begin("http://localhost:5678");
client.setAuthorization("user", "pass"); // Will set _base64Authorization to base64encode(user+ ':' + pass)
client.setAuthorization("base64encoded_String"); // Will set _base64Authorization to the arg value
client.GET(); // Will set the Authorization header to "Basic " + _base64Authorization
}

```

### Debug Messages

No debug messages

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.