Add OAuth2 client_credentials support to step.http_call#183
Conversation
Co-authored-by: intel352 <77607+intel352@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR adds native OAuth2 client_credentials flow support to the step.http_call pipeline step, enabling pipelines to call OAuth2-protected APIs (like Salesforce) without manual token management. The implementation includes token caching with TTL-based expiry, automatic retry on 401 responses, and comprehensive test coverage.
Changes:
- Added OAuth2 client credentials authentication with configurable token URL, client ID/secret, and scopes
- Implemented thread-safe token caching with TTL derived from OAuth2
expires_inresponses (with 10s expiry buffer) - Added automatic token invalidation and retry on 401 unauthorized responses
- Made HTTP client injectable to enable unit testing without real network calls
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
module/pipeline_step_http_call.go |
Core implementation: adds oauthConfig struct, thread-safe tokenCache, token fetch/refresh logic, 401-retry flow, and injectable httpClient field |
module/pipeline_step_http_call_test.go |
Comprehensive test coverage for basic GET, error responses, OAuth2 token fetch/caching/expiry/retry, scope forwarding, and missing auth fields |
cmd/wfctl/type_registry.go |
Updated ConfigKeys for step.http_call to include the new auth configuration field |
|
@copilot apply changes based on the comments in this thread Also, make sure that this functionality is not incompatible with multi-tenancy. |
…Auth2 http_call step Co-authored-by: intel352 <77607+intel352@users.noreply.github.com>
Applied all three review comments in 06274fe:
|
Pipelines calling OAuth2-protected APIs (e.g. Salesforce) currently require a separate token-fetch step with no caching, or a custom Go step. This adds native
oauth2_client_credentialssupport directly tostep.http_call.Changes
module/pipeline_step_http_call.gooauthConfigstruct (token URL, client ID/secret, scopes) with a credential fingerprint used as a cache keyglobalOAuthCache(oauthTokenCache) shared across allHTTPCallStepinstances, keyed by credential fingerprint (token_url + client_id + client_secret + scopes) — tokens are reused across pipeline executions for the same credentialssingleflight.Groupto coalesce concurrent token fetches: only one network call is made to the token endpoint even under concurrent load (double-checked locking pattern)auth.type = "oauth2_client_credentials"is configured; reuses cached token until expiry (with 10s buffer)401, invalidates the shared cache entry and fetches a fresh token directly (bypassing singleflight for an unconditional refresh), then retries the request oncehttpClientan injectable field (was hardcoded tohttp.DefaultClient) to enable unit testing; request timeouts are enforced via context (set bycontext.WithTimeoutat the top ofExecute)module/pipeline_step_http_call_test.gocmd/wfctl/type_registry.goauthtoConfigKeysforstep.http_callExample config
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.