Skip to content

[APPS] Default apps plugin auth to OAuth without keys#427

Open
sdkennedy2 wants to merge 1 commit into
masterfrom
sdkennedy2/apps-plugin-oauth-default
Open

[APPS] Default apps plugin auth to OAuth without keys#427
sdkennedy2 wants to merge 1 commit into
masterfrom
sdkennedy2/apps-plugin-oauth-default

Conversation

@sdkennedy2

@sdkennedy2 sdkennedy2 commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

Motivation

Datadog Apps local development and upload should use OAuth by default when API/App keys are not configured. This matches the intended customer setup where npm run dev and npm run upload can start an OAuth browser flow instead of failing with missing key guidance.

Changes

The apps plugin now resolves apps.authOverrides.method in this order:

DD_APPS_AUTH_METHOD / DATADOG_APPS_AUTH_METHOD
apps.authOverrides.method
apiKey when both API and App keys are available
oauth otherwise

Explicit config and environment overrides still win, and users can force API/App-key auth with DD_APPS_AUTH_METHOD=apiKey. The README documents the conditional default, and the validation tests cover configured keys, env keys, incomplete auth, explicit override precedence, and env isolation.

QA Instructions

In a Datadog App using @datadog/vite-plugin, run npm run dev or npm run upload without DD_API_KEY/DD_APP_KEY; the apps plugin should select OAuth. Set both keys and rerun to confirm API/App-key auth remains the default. Set DD_APPS_AUTH_METHOD=apiKey or DD_APPS_AUTH_METHOD=oauth to confirm explicit method selection still wins.

Blast Radius

This affects the Datadog Apps plugin auth default for app upload and local backend function execution. Other build plugin products keep their existing auth behavior because the override remains scoped to apps.authOverrides.method.

Documentation

sdkennedy2 commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@sdkennedy2 sdkennedy2 changed the title Default apps plugin auth to OAuth without keys [APPS] Default apps plugin auth to OAuth without keys Jun 18, 2026
@sdkennedy2

Copy link
Copy Markdown
Collaborator Author

@codex review
@cursor review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: ad82fc266c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@sdkennedy2 sdkennedy2 marked this pull request as ready for review June 18, 2026 16:06
@sdkennedy2 sdkennedy2 requested review from a team and yoannmoinet as code owners June 18, 2026 16:06
### apps.authOverrides.method

> default: `apiKey`
> default: `apiKey` when both `DD_API_KEY` and `DD_APP_KEY` are configured, otherwise `oauth`

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

if OAuth is loaded when nothing is configured, then I think the default is oauth now.

Suggested change
> default: `apiKey` when both `DD_API_KEY` and `DD_APP_KEY` are configured, otherwise `oauth`
> default: `oauth`

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Wouldn't it be when DD_API_KEY and DD_APP_KEY are set, the default is apiKey, otherwise the default is oauth?

@yoannmoinet yoannmoinet left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM.
I have a comment, but it's not blocking.

Could be a follow-up to avoid duplications and enforce existing patterns.

Comment on lines +7 to +29
const authEnvVars = [
'DATADOG_API_KEY',
'DD_API_KEY',
'DATADOG_APP_KEY',
'DD_APP_KEY',
'DATADOG_APPS_AUTH_METHOD',
'DD_APPS_AUTH_METHOD',
] as const;

const savedAuthEnv = Object.fromEntries(
authEnvVars.map((key) => [key, process.env[key]]),
) as Record<(typeof authEnvVars)[number], string | undefined>;

const restoreAuthEnv = () => {
for (const key of authEnvVars) {
const value = savedAuthEnv[key];
if (value === undefined) {
delete process.env[key];
} else {
process.env[key] = value;
}
}
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We have this cleanEnv() system here:

export const cleanEnv = () => {
const previousEnv = {
DATADOG_API_KEY: process.env.DATADOG_API_KEY,
DD_API_KEY: process.env.DD_API_KEY,
DATADOG_APP_KEY: process.env.DATADOG_APP_KEY,
DD_APP_KEY: process.env.DD_APP_KEY,
DATADOG_APPS_UPLOAD_ASSETS: process.env.DATADOG_APPS_UPLOAD_ASSETS,
DD_APPS_UPLOAD_ASSETS: process.env.DD_APPS_UPLOAD_ASSETS,
DATADOG_SITE: process.env.DATADOG_SITE,
DD_SITE: process.env.DD_SITE,
};
delete process.env.DATADOG_API_KEY;
delete process.env.DD_API_KEY;
delete process.env.DATADOG_APP_KEY;
delete process.env.DD_APP_KEY;
delete process.env.DATADOG_APPS_UPLOAD_ASSETS;
delete process.env.DD_APPS_UPLOAD_ASSETS;
delete process.env.DATADOG_SITE;
delete process.env.DD_SITE;
return () => {
process.env.DATADOG_API_KEY = previousEnv.DATADOG_API_KEY;
process.env.DD_API_KEY = previousEnv.DD_API_KEY;
process.env.DATADOG_APP_KEY = previousEnv.DATADOG_APP_KEY;
process.env.DD_APP_KEY = previousEnv.DD_APP_KEY;
process.env.DATADOG_APPS_UPLOAD_ASSETS = previousEnv.DATADOG_APPS_UPLOAD_ASSETS;
process.env.DD_APPS_UPLOAD_ASSETS = previousEnv.DD_APPS_UPLOAD_ASSETS;
process.env.DATADOG_SITE = previousEnv.DATADOG_SITE;
process.env.DD_SITE = previousEnv.DD_SITE;
};
};

Currently, we only call it in beforeAll/afterAll but maybe we could extend/modify it to suit your use-case?
Not sure if it would have a real impact if we were to do it on beforeEach/afterEach instead.

(And also make it leverage OVERRIDE_VARIABLES instead of duplicating them)

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.

3 participants