Skip to content

Conversation

@tjb9dc
Copy link
Collaborator

@tjb9dc tjb9dc commented Dec 8, 2025

Description

Refs: Requested by @tjb9dc via Slack

Implements OAuth client credentials authentication in the Go SDK generator with automatic token refresh support, addressing the TODO at EndpointSnippetGenerator.ts#L335-L337.

Link to Devin run: https://app.devin.ai/sessions/cbaf1544965b49c2a2eef83a22b1b199

Changes Made

  • Added new OAuthTokenProvider in core/oauth.go that manages OAuth tokens with:
    • Thread-safe token access using sync.Mutex
    • 2-minute buffer before expiry to trigger refresh (matching Python/TypeScript implementations)
    • Double-check locking pattern for efficient concurrent access
  • Updated WriteRequestOptionsDefinition to add ClientID, ClientSecret, and internal OAuthTokenProvider fields to RequestOptions
  • Added ClientCredentialsOption struct and WithClientCredentials(clientID, clientSecret) option function for a cleaner user-facing API
  • Added computeOAuthClientCredentialsConfig function to extract OAuth configuration from IR auth-schemes
  • Updated EndpointSnippetGenerator.ts to generate WithClientCredentials constructor arguments instead of warning
  • Bumped version to 1.19.0 with changelog entry

Updates Since Last Revision

Addressed PR feedback to auto-generate OAuth token refresh from auth-schemes config:

  • Added OAuthClientCredentialsConfig struct to hold OAuth endpoint configuration extracted from IR
  • Added computeOAuthClientCredentialsConfig function that extracts token endpoint, request/response field names from IR
  • Updated WriteClient to accept OAuth config and generate token provider initialization code
  • Dynamic snippets for oauth-client-credentials-default now use WithClientCredentials(clientID, clientSecret) instead of WithOAuthTokenProvider

Testing

  • Seed tests pass for oauth-client-credentials-default fixture
  • Seed tests pass for oauth-client-credentials-environment-variables fixture
  • Lint checks pass (pnpm run check)
  • Unit tests added/updated (no new unit tests added)

Human Review Checklist

  • Fixture inconsistency: oauth-client-credentials-environment-variables still shows WithOAuthTokenProvider in dynamic snippets while oauth-client-credentials-default uses WithClientCredentials - verify this is expected or needs fixing
  • OAuth config extraction: computeOAuthClientCredentialsConfig has many early return points that return nil - verify the function correctly extracts config for all OAuth fixtures
  • Client constructor: Verify the OAuth token provider initialization code is being generated in the root client constructor when OAuth is configured
  • Thread safety: The fast path in GetToken() reads fields without lock - verify the double-check pattern is sufficient
  • Token expiry edge case: If ExpiresIn < 120 seconds, expiry time could be in the past immediately

@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

arguments_: [
go.TypeInstantiation.string(values.clientId),
go.TypeInstantiation.string(values.clientSecret),
go.codeblock("nil") // refreshFunc will be set by the SDK internally
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This doesn't seem great for users

devin-ai-integration bot and others added 2 commits December 9, 2025 00:17
…redentials API

Address PR feedback to improve the user-facing API for OAuth client credentials:
- Replace WithOAuthTokenProvider(core.NewOAuthTokenProvider(..., nil)) with simpler WithClientCredentials(clientID, clientSecret)
- Store ClientID and ClientSecret in RequestOptions with internal OAuthTokenProvider field
- Update EndpointSnippetGenerator to emit the new simpler API
- Hide internal OAuthTokenProvider details from users

This matches the Python/TypeScript pattern where users just provide credentials at construction time.

Co-Authored-By: [email protected] <[email protected]>
- Add OAuthClientCredentialsConfig struct to hold OAuth configuration
- Add computeOAuthClientCredentialsConfig function to extract OAuth config from IR
- Update WriteClient to accept OAuth config and generate token provider initialization
- Update dynamic snippets to use WithClientCredentials instead of WithOAuthTokenProvider
- The SDK now automatically creates a default refreshFunc from the OAuth configuration

Co-Authored-By: [email protected] <[email protected]>
@fern-support
Copy link
Collaborator

closing as we cooked Devin on this one

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants