Creating example for new TokenProvider plugin#153
Open
stuart-wells wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new extensibility sample demonstrating how to plug in Temporal Server’s auth.TokenProvider to attach bearer tokens to outbound cross-cluster (replication) RPCs, along with dependency updates needed to consume the (pre-release) Temporal Server changes that introduced TokenProvider.
Changes:
- Add a new
extensibility/tokenprovidersample (provider implementation + standalone server wiring + tests + test config). - Update the extensibility index README to link the new TokenProvider sample.
- Update
extensibility/go.mod/go.sumto pin Temporal Server/API versions that include the new TokenProvider support, and adjust the authorizer claim-mapper TLS subject handling.
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| README.md | Adds a link to the new Token Provider sample. |
| extensibility/tokenprovider/README.md | Documents the TokenProvider sample, caching behavior, and required config knobs. |
| extensibility/tokenprovider/myTokenProvider.go | Implements a file-backed TokenProvider with expiry-aware caching via oauth2.ReuseTokenSource. |
| extensibility/tokenprovider/myTokenProvider_test.go | Unit tests for file token reading, caching behavior, and JWT exp parsing. |
| extensibility/tokenprovider/server/main.go | Wires temporal.WithTokenProvider(...) into a sample server. |
| extensibility/tokenprovider/server/main_test.go | Boots the sample server and validates it becomes reachable with TokenProvider required. |
| extensibility/tokenprovider/server/testdata/config.yaml | Minimal server config for tests, including remoteClusterAuth+TLS stub. |
| extensibility/go.mod | Pins Temporal dependencies (incl. TokenProvider commit) and updates module requirements. |
| extensibility/go.sum | Updates dependency checksums to match the new module graph. |
| extensibility/authorizer/myClaimMapper.go | Switches TLS-based claim extraction to use TLSSubject when present (mTLS). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+25
to
+49
| import ( | ||
| "log" | ||
| "os" | ||
|
|
||
| "go.temporal.io/server/common/config" | ||
| "go.temporal.io/server/temporal" | ||
|
|
||
| "github.com/temporalio/service-samples/tokenprovider" | ||
| ) | ||
|
|
||
| // tokenFileEnv names the env var that points at the file containing the | ||
| // bearer token. The fileTokenProvider re-reads it on every outbound RPC, so | ||
| // rotation just means overwriting the file. | ||
| const tokenFileEnv = "TOKEN_FILE" | ||
|
|
||
| func newServer(configFile string, opts ...temporal.ServerOption) (temporal.Server, error) { | ||
| cfg, err := config.Load(config.WithConfigFile(configFile)) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| tokenFile := os.Getenv(tokenFileEnv) | ||
| if tokenFile == "" { | ||
| log.Fatalf("%s must be set to the path of a bearer-token file", tokenFileEnv) | ||
| } |
| module github.com/temporalio/service-samples | ||
|
|
||
| go 1.25.8 | ||
| go 1.26.4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TODO: Before merging, need to update go.mod to the actual release that TokenProvider is included with.
What was changed
Added samples for using JWT to auth replication/internode traffic
Why?
TokenProvider was added to OSS in temporalio/temporal@74a7108 and will soon be released. Prepping a sample for reference in setting up a server using the plugin.
Checklist
How was this tested:
Used samples to create local servers and ran validation against those servers.
Any docs updates needed?
Doc changes are already approved.