Skip to content

feat(docs): update JS SDK examples to interceptor auth pattern#270

Draft
marythought wants to merge 7 commits intomainfrom
feat/docs-interceptor-auth-pattern
Draft

feat(docs): update JS SDK examples to interceptor auth pattern#270
marythought wants to merge 7 commits intomainfrom
feat/docs-interceptor-auth-pattern

Conversation

@marythought
Copy link
Copy Markdown
Contributor

@marythought marythought commented Apr 1, 2026

Summary

Updates all JavaScript/TypeScript code examples across SDK documentation to use the new Connect RPC interceptor-based authentication pattern with built-in token provider factories, replacing the deprecated AuthProvider approach and manual token fetching.

What changed

  • Manual getAccessToken() implementations → clientCredentialsTokenProvider(), refreshTokenProvider(), externalJwtTokenProvider() factory functions
  • AuthProviders.clientSecretAuthProvider()authTokenInterceptor() with token provider factories as the primary JS auth pattern
  • "Define once, pass everywhere" idiom: create an auth config object once, reuse for OpenTDF, PlatformClient, and standalone functions
  • Removed all await client.ready — no longer needed with interceptors (the DPoP ordering footgun is gone)
  • AuthProvider examples preserved in "Legacy" sections for backwards compatibility
  • DPoP section updated to show authTokenDPoPInterceptor() with clientCredentialsTokenProvider()
  • Authentication decision guide updated to reference new factory functions

Files modified

Docs:

  • docs/sdks/authentication.mdx — all 4 auth patterns + new DPoP section + legacy section
  • docs/sdks/quickstart/javascript.mdx — all step-by-step examples
  • docs/sdks/discovery.mdx — standalone function calls
  • docs/sdks/tdf.mdx — encrypt/decrypt examples
  • docs/sdks/authorization.mdx — flipped interceptors to primary, AuthProvider to legacy
  • docs/sdks/platform-client.mdx — init pattern, removed ready guidance
  • docs/sdks/policy.mdx — all PlatformClient construction
  • docs/sdks/troubleshooting.mdx — token refresh + validateAttributes
  • docs/guides/authentication-guide.mdx — decision guide references to factory functions

Code samples:

  • All 7 files in code_samples/policy_code/

Test plan

🤖 Generated with Claude Code

Updates all JavaScript/TypeScript code examples to use the new
Connect RPC interceptor-based authentication introduced in
opentdf/web-sdk#899, replacing the deprecated AuthProvider pattern.

Key changes:
- authTokenInterceptor as primary auth mechanism
- "define once, pass everywhere" pattern for shared auth config
- Remove await client.ready (no longer needed with interceptors)
- AuthProvider examples moved to legacy sections
- Standalone functions (listAttributes, etc.) use AuthConfig

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 1, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 94cd86f7-a2bc-4d6e-8615-716031f632ee

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/docs-interceptor-auth-pattern

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the JavaScript SDK documentation to replace the deprecated AuthProvider interface with a new interceptor-based authentication model. Changes include updating code samples across multiple files to use authTokenInterceptor, introducing authTokenDPoPInterceptor, and adding a SortDirection enum to the policy OpenAPI specification. Reviewer feedback focuses on improving the provided getAccessToken examples by recommending the use of URLSearchParams for more robust request body encoding and emphasizing the need for token caching in production environments to prevent performance issues.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

📄 Preview deployed to https://opentdf-docs-pr-270.surge.sh

eugenioenko
eugenioenko previously approved these changes Apr 1, 2026
Copy link
Copy Markdown
Contributor

@eugenioenko eugenioenko left a comment

Choose a reason for hiding this comment

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

Changes look great!

Left a small inline comment, which gemini has something among the same line we can look into later

- Use URLSearchParams instead of raw string body in all getAccessToken
- Add caching note to token provider functions
- Use ...auth spread pattern in platform-client.mdx
- Add getAccessToken definition to platform-client.mdx
- Add setup tip to discovery.mdx and comment to authorization.mdx
  explaining getAccessToken comes from /sdks/authentication

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
marythought and others added 4 commits April 1, 2026 10:21
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace `...auth` spread (undefined in snippet context) with explicit
`interceptors: [authTokenInterceptor(() => myAuth.getAccessToken())]`
in all policy code samples and policy.mdx JS blocks.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace manual getAccessToken() implementations with the new
clientCredentialsTokenProvider, refreshTokenProvider, and
externalJwtTokenProvider factory functions from web-sdk#906.

These handle caching, auto-refresh, and concurrent request
deduplication out of the box — no more hand-rolled OAuth fetch code
in every example.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Mary Dickson <mary.dickson@virtru.com>
Copy link
Copy Markdown
Contributor

@eugenioenko eugenioenko left a comment

Choose a reason for hiding this comment

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

interceptors: [authTokenInterceptor(clientCredentialsTokenProvider({
    clientId: 'opentdf', clientSecret: 'secret',
    oidcOrigin: 'http://localhost:8080/auth/realms/opentdf',
  }))],

The nice thing about this example is that it's self-contained. Thats powerful.
Copy/past and it works. 10 of out 10 honestly.

The one thing that raises a small concern for me is that it's a private client credentials flow. We're adding multiple examples of it, but this goes against the nature of Web SDK being for the Browser.

I'm torn a little, one on side, this is self-contained, on the other side it gives an example of how to use WebSDK in the wrong environment or the wrong way. We probably would need to add comments to all examples // don't use this in production/browser and that would defeat the purpose of self-contained example

A compromise. Can we define that only once (instead of on each example) and have something like this on the funciton

The examples below use clientCredentialsTokenProvider for brevity. This requires a client secret and is intended for server-side use only. In browser applications, replace with your OIDC library's token

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.

2 participants