Skip to content

feat(middleware): add BearerTokenMiddleware for OAuth2 bearer token injection#1288

Open
robhughadams wants to merge 1 commit intoDataDog:masterfrom
robhughadams:feat/bearer-token-middleware
Open

feat(middleware): add BearerTokenMiddleware for OAuth2 bearer token injection#1288
robhughadams wants to merge 1 commit intoDataDog:masterfrom
robhughadams:feat/bearer-token-middleware

Conversation

@robhughadams
Copy link

Summary

Add BearerTokenMiddleware to support OAuth2 bearer token injection at the HTTP middleware layer. This enables client consumers to authenticate with OAuth2 bearer tokens uniformly across all API endpoints, without requiring dual-path authentication logic in each call site.

This change is proposed to unblock datadog-labs/pup#133, which fixes datadog-labs/pup#72 ("Can't query logs with OAuth").

Changes

  • src/datadog/middleware.rs (new): BearerTokenMiddleware struct implementing reqwest_middleware::Middleware — injects Authorization: Bearer <token> header on all outgoing requests when a token is configured
  • src/datadog/configuration.rs: Added bearer_token: Option<String> field, set_bearer_token() setter, and DD_ACCESS_TOKEN environment variable support
  • src/datadog/mod.rs: Exported pub mod middleware and re-exported BearerTokenMiddleware
  • Cargo.toml: Added async-trait = "0.1" and task-local-extensions = "0.1" dependencies

Related Issues

@robhughadams robhughadams requested review from a team as code owners February 27, 2026 17:15
@robhughadams robhughadams marked this pull request as draft February 27, 2026 17:16
@robhughadams robhughadams force-pushed the feat/bearer-token-middleware branch from 96b2fd8 to adad828 Compare February 27, 2026 17:17
@robhughadams robhughadams changed the title refactor(middleware): add BearerTokenMiddleware for OAuth2 bearer token injection feat(middleware): add BearerTokenMiddleware for OAuth2 bearer token injection Feb 27, 2026
Comment on lines +1 to +3
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2019-Present Datadog, Inc.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2019-Present Datadog, Inc.
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2026-Present Datadog, Inc.

Although I think you can also just remove this section.

pub use configuration::{APIKey, Configuration, DEFAULT_USER_AGENT};

pub mod middleware;
pub use middleware::BearerTokenMiddleware;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do we attach this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Can't query logs with OAuth

2 participants