-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
lib/api: Allow Bearer authentication style with API key
#9002
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Currently, historically, we look for the `X-API-Key` header to authenticate with an API key. There's nothing wrong with this, but in some scenarios it's easier to produce an `Authorization` header with a `Bearer $token` content, which is nowadays more common. This change adds support for both, so that we will accept an API key either in our custom header or as a bearer token.
lib/api/api_test.go
Outdated
| t.Fatal("Getting /rest/system/config with API key should succeed, not", resp.Status) | ||
| } | ||
|
|
||
| // Calling on /rest with the API key as a bearer token should succeed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should have tests for wrong API keys? As this changes what is accepted, we should make sure nothing creeps in later that accepts too much.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added, and also improved & modernized the tests a little
* main: cmd/strelaysrv: Handle accept error with debug set (fixes syncthing#9001) (syncthing#9004) lib/api: Fix data race in TestCSRFRequired (syncthing#9006) gui: Show full error for failed items (syncthing#9005) lib/api: Allow `Bearer` authentication style with API key (syncthing#9002)
* main: build: Increase Go version to 1.20.7 lib/config: Allow sharing already encrypted folder with untrusted devices (fixes syncthing#8965) (syncthing#9012) gui: Use case-insensive and backslash-agnostic versions filter (fixes syncthing#7973) (syncthing#8995) gui, man, authors: Update docs, translations, and contributors build: Run govulncheck (fixes syncthing#8983) build: Run build & tests on main branch nightly build: Send test logs to Grafana Loki for statistics all: Refactor the protocol/model interface a bit (ref syncthing#8981) (syncthing#9007) lib/connections: Fix building with `-tags noquic` (syncthing#9009) gui: Fix tooltips on buttons inside button groups (ref syncthing#7984) (syncthing#9008) cmd/strelaysrv: Handle accept error with debug set (fixes syncthing#9001) (syncthing#9004) lib/api: Fix data race in TestCSRFRequired (syncthing#9006) gui: Show full error for failed items (syncthing#9005) lib/api: Allow `Bearer` authentication style with API key (syncthing#9002)
Currently, historically, we look for the
X-API-Keyheader to authenticate with an API key. There's nothing wrong with this, but in some scenarios it's easier to produce anAuthorizationheader with aBearer $tokencontent, which is nowadays more common. This change adds support for both, so that we will accept an API key either in our custom header or as a bearer token.