Skip to content

[APPS] Add OAuth auth for Apps#393

Open
otorrillas wants to merge 1 commit into
codex/optional-deps-integrityfrom
oriol.torrillas/apps-oauth-pkce-upload
Open

[APPS] Add OAuth auth for Apps#393
otorrillas wants to merge 1 commit into
codex/optional-deps-integrityfrom
oriol.torrillas/apps-oauth-pkce-upload

Conversation

@otorrillas

@otorrillas otorrillas commented Jun 2, 2026

Copy link
Copy Markdown

Summary

Depends on #421.

Adds OAuth support for Datadog Apps while keeping the optional dependency integrity support in its own PR:

  • adds the core OAuth PKCE token flow and optional keychain cache
  • adds oauth-request.ts, which owns OAuth token resolution and doOAuthRequest
  • extends doRequest to accept request-ready auth via API/app keys or an already resolved OAuth access token
  • adds Apps-scoped auth selection via apps.authOverrides.method and DD_APPS_AUTH_METHOD / DATADOG_APPS_AUTH_METHOD, defaulting to API-key auth
  • wires OAuth auth into Apps uploads and the Apps Vite dev-server execution path
  • keeps oauth4webapi as a regular dependency and @napi-rs/keyring as an optional dependency

Validation

  • yarn workspace @dd/tests test:unit packages/core/src/helpers/request.test.ts packages/core/src/helpers/oauth-request.test.ts packages/plugins/error-tracking/src/sourcemaps/sender.test.ts packages/plugins/apps/src/auth.test.ts packages/plugins/apps/src/upload.test.ts packages/plugins/apps/src/index.test.ts packages/plugins/apps/src/validate.test.ts packages/plugins/apps/src/vite/dev-server.test.ts packages/plugins/apps/src/vite/index.test.ts
  • yarn cli integrity
  • git diff --check

@otorrillas otorrillas requested review from a team and yoannmoinet as code owners June 2, 2026 06:52
@datadog-prod-us1-4

datadog-prod-us1-4 Bot commented Jun 2, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 4cfb545 | Docs | Datadog PR Page | Give us feedback!

@otorrillas otorrillas force-pushed the oriol.torrillas/apps-oauth-pkce-upload branch 4 times, most recently from 53ad0e4 to 490c3f3 Compare June 2, 2026 08:22

@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.

Doing a quick review first, to tackle my biggest comments 😃

Comment thread packages/core/src/helpers/oauth-request.ts
Comment thread packages/core/src/types.ts Outdated
Comment thread packages/core/src/types.ts Outdated
Comment thread packages/plugins/apps/src/vite/dev-server.ts Outdated
@sdkennedy2 sdkennedy2 changed the title Add OAuth PKCE auth for Apps uploads [APPS] Add OAuth PKCE auth for Apps uploads Jun 11, 2026
Comment thread packages/core/src/helpers/request.ts Outdated
Comment thread packages/plugins/apps/src/vite/handle-upload.ts Outdated
Comment thread packages/plugins/apps/src/index.test.ts Outdated
Comment thread packages/plugins/apps/src/types.ts Outdated
Comment thread packages/plugins/apps/src/upload.ts Outdated
Comment thread packages/plugins/apps/src/validate.ts Outdated
Comment thread packages/plugins/apps/README.md Outdated
Comment thread packages/core/src/helpers/oauth.ts Outdated
Comment thread packages/core/src/helpers/request.ts Outdated
"dependencies": {
"@datadog/js-instrumentation-wasm": "1.0.8",
"@jridgewell/remapping": "2.3.5",
"@napi-rs/keyring": "1.3.0",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If these are in the core package do we need these as dependencies within all the build specific plugins (esbuild-plugin, rollup-plugin, etc)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yeah, I think we still need them here. The published packages bundle the internal @dd/* packages rather than depending on @dd/core at runtime, and the integrity dependency sync flattens external deps from internal workspaces into each published package. Since the OAuth helper in core dynamically loads oauth4webapi and @napi-rs/keyring, the published packages need to declare them so they’re installed for consumers.

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.

This is pretty bad.
We need to find a way to make this optional only.

Comment thread packages/core/src/helpers/oauth.ts Outdated
Comment thread packages/plugins/apps/src/upload.ts Outdated
@sdkennedy2

Copy link
Copy Markdown
Collaborator

@codex review
@cursor review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 703d88302a

ℹ️ 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".

Comment thread packages/core/src/helpers/oauth.ts Outdated
Comment thread packages/core/src/types.ts Outdated
Comment thread packages/core/src/helpers/request.ts Outdated
Comment thread packages/core/src/helpers/oauth.ts Outdated
Comment on lines +12 to +25
const OAUTH_PACKAGE_NAME = 'oauth4webapi';
const KEYRING_PACKAGE_NAME = '@napi-rs/keyring';

type OAuthAuthorizationServer = import('oauth4webapi').AuthorizationServer;
type OAuthClient = import('oauth4webapi').Client;
type OAuthModule = typeof import('oauth4webapi');
type OAuthTokenEndpointResponse = import('oauth4webapi').TokenEndpointResponse;
type KeyringModule = typeof import('@napi-rs/keyring');

// Load through a variable specifier so bundlers leave these as runtime requires
// instead of inlining them — notably the native `@napi-rs/keyring` binary. Node
// caches modules by specifier, so repeated calls reuse the same instance.
const loadOauth = () => import(OAUTH_PACKAGE_NAME) as Promise<OAuthModule>;
const loadKeyring = () => import(KEYRING_PACKAGE_NAME) as Promise<KeyringModule>;

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.

Why do we do this if the dependency is required in all the package.json?

Comment thread packages/core/src/helpers/oauth-request.ts
Comment thread packages/plugins/apps/src/upload.ts Outdated
return { errors, warnings };
}

if (!requestAuth) {

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.

Shouldn't this be reflected on the type instead?

Comment thread packages/core/src/helpers/request.ts Outdated
Comment thread packages/plugins/apps/README.md Outdated
Comment on lines +29 to +34
auth?: {
apiKey?: string;
appKey?: string;
site?: string;
}

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.

This will break the root README once included in it.
Because we copy this ## Configuration block into the global configuration block of the root.

Comment thread packages/plugins/apps/README.md Outdated

> default: `apiKey`

Authentication method for uploading app bundles. Scoped to the `apps` plugin rather than the shared `auth` config, because not every Datadog endpoint supports OAuth.

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.

Not sure this is a necessary detail...

Suggested change
Authentication method for uploading app bundles. Scoped to the `apps` plugin rather than the shared `auth` config, because not every Datadog endpoint supports OAuth.
Authentication method for uploading app bundles.

Comment on lines +401 to +402
const { AsyncEntry } = await loadKeyring();
return new AsyncEntry(OAUTH_KEYCHAIN_SERVICE, getOAuthCredentialAccount(site, options));

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.

What is keyring necessary for?
No alternative?

"dependencies": {
"@datadog/js-instrumentation-wasm": "1.0.8",
"@jridgewell/remapping": "2.3.5",
"@napi-rs/keyring": "1.3.0",

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.

This is pretty bad.
We need to find a way to make this optional only.

Comment thread packages/core/src/helpers/request.ts Outdated
Comment thread packages/core/src/helpers/request.ts
Comment thread packages/core/src/helpers/request.ts Outdated
Comment thread packages/core/src/types.ts Outdated
Comment thread packages/core/package.json
Comment thread packages/plugins/apps/src/auth.ts
Comment thread packages/plugins/apps/src/auth.ts Outdated
Comment thread packages/plugins/apps/src/upload.ts Outdated
return { errors, dependencies };
};

type DependencyType = 'dependencies' | 'optionalDependencies';

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Would it be worth separating out optionalDependencies integrity support into a separate PR?

@sdkennedy2 sdkennedy2 force-pushed the oriol.torrillas/apps-oauth-pkce-upload branch 2 times, most recently from b2ac87c to 2cc5df7 Compare June 16, 2026 18:22
@sdkennedy2 sdkennedy2 changed the title [APPS] Add OAuth PKCE auth for Apps uploads [CORE] Add OAuth request helpers Jun 16, 2026
@sdkennedy2 sdkennedy2 changed the base branch from master to codex/optional-deps-integrity June 16, 2026 18:22
@sdkennedy2 sdkennedy2 force-pushed the oriol.torrillas/apps-oauth-pkce-upload branch 2 times, most recently from bdeb952 to fb3a06d Compare June 16, 2026 21:05
@sdkennedy2 sdkennedy2 changed the title [CORE] Add OAuth request helpers [APPS] Add OAuth auth for Apps Jun 16, 2026
viteBuild: typeof build,
getBackendFunctions: () => BackendFunction[],
auth: AuthOptionsWithDefaults,
authMethod: AuthMethod,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Couldn't we just thread through doAuthenticatedRequest like we do in other places?

Comment on lines +157 to +158
: getAuthenticatedRequest(options.authOverrides.method, auth, log)) ||
doMissingAuthenticationRequest;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I wonder if getAuthenticatedRequest should just throw if we are missing auth information. We probably need to differentiate between a 500 and 400 error in some cases, perhaps we should create error classes.

@sdkennedy2 sdkennedy2 force-pushed the oriol.torrillas/apps-oauth-pkce-upload branch 3 times, most recently from 2e23fc6 to e467ffc Compare June 16, 2026 21:33
func: BackendFunction,
args: unknown[],
auth: AuthConfig,
site: Site,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It looks like we missed some places. We were support to revert site: Site, changes back to auth: AuthConfig,

@sdkennedy2 sdkennedy2 force-pushed the oriol.torrillas/apps-oauth-pkce-upload branch from e467ffc to 4cfb545 Compare June 16, 2026 21:38
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