feat(docs): update JS SDK examples to interceptor auth pattern#270
feat(docs): update JS SDK examples to interceptor auth pattern#270marythought wants to merge 7 commits intomainfrom
Conversation
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>
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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>
|
📄 Preview deployed to https://opentdf-docs-pr-270.surge.sh |
- 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>
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>
There was a problem hiding this comment.
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
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
AuthProviderapproach and manual token fetching.What changed
getAccessToken()implementations →clientCredentialsTokenProvider(),refreshTokenProvider(),externalJwtTokenProvider()factory functionsAuthProviders.clientSecretAuthProvider()→authTokenInterceptor()with token provider factories as the primary JS auth patternauthconfig object once, reuse forOpenTDF,PlatformClient, and standalone functionsawait client.ready— no longer needed with interceptors (the DPoP ordering footgun is gone)AuthProviderexamples preserved in "Legacy" sections for backwards compatibilityauthTokenDPoPInterceptor()withclientCredentialsTokenProvider()Files modified
Docs:
docs/sdks/authentication.mdx— all 4 auth patterns + new DPoP section + legacy sectiondocs/sdks/quickstart/javascript.mdx— all step-by-step examplesdocs/sdks/discovery.mdx— standalone function callsdocs/sdks/tdf.mdx— encrypt/decrypt examplesdocs/sdks/authorization.mdx— flipped interceptors to primary, AuthProvider to legacydocs/sdks/platform-client.mdx— init pattern, removed ready guidancedocs/sdks/policy.mdx— all PlatformClient constructiondocs/sdks/troubleshooting.mdx— token refresh + validateAttributesdocs/guides/authentication-guide.mdx— decision guide references to factory functionsCode samples:
code_samples/policy_code/Test plan
🤖 Generated with Claude Code