feat(bearerauth): add mixed credential example - #9
Merged
Conversation
Demonstrate one protected route accepting JWT access tokens and Personal API Keys through sdk-go/bearerauth. Document secure configuration, tokeninfo and introspection flows, error mapping, and credential handling. Cover the client and server adapters with configuration, redaction, redirect, concurrency, and HTTP mapping tests.
| logger.Printf( | ||
| "server listening addr=%s personal_api_key_verification=%s", | ||
| listener.Addr(), | ||
| personalAPIKeyMode, |
There was a problem hiding this comment.
Pull request overview
Adds a new standalone Go example (go-bearerauth/) demonstrating “mixed credential” API protection: the same protected route accepts either JWT access tokens (offline verification after discovery/JWKS) or Signet Personal API Keys (online tokeninfo/introspection per request), with explicit net/http integration and RFC 6750-style error mapping.
Changes:
- Added a complete
go-bearerauthclient/server example with bounded I/O, redirect refusal, context identity propagation, and typed error → HTTP mapping. - Added comprehensive unit tests for both the server adapter and the client behavior (including redaction and redirect refusal).
- Updated root documentation to list and distinguish the new mixed-credential example; added an implementation/verification plan.
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| README.md | Adds go-bearerauth to the example matrix and documents required env vars + positioning vs other resource-server examples. |
| plan.md | New implementation plan and verification strategy for the go-bearerauth example. |
| go-bearerauth/server/main.go | Implements the net/http adapter around bearerauth.Verifier, config validation, identity context propagation, and RFC 6750-style error mapping. |
| go-bearerauth/server/main_test.go | Tests config validation, header parsing, error mapping, concurrency safety, and fail-closed behavior. |
| go-bearerauth/client/main.go | Implements a safe example client: URL validation, redirect refusal, bounded response reads, and credential redaction. |
| go-bearerauth/client/main_test.go | Tests client exit codes, request construction, safe output/redaction, truncation, and redirect refusal. |
| go-bearerauth/README.md | Adds detailed setup/run/troubleshooting/security documentation for the mixed-credential flow and tokeninfo vs introspection. |
| go-bearerauth/.env.example | Provides a documented env template for both server policy and client invocation. |
| go-bearerauth/go.mod | Introduces a standalone module pinned to github.com/go-signet/sdk-go v1.1.0 plus supporting deps. |
| go-bearerauth/go.sum | Adds checksums for the new module dependencies. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Remove the internal planning document from the example changes
- Align Markdown tables for consistent rendering - Compact illustrative scope arrays without changing content
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.
Summary
Add a complete
go-bearerauthexample usinggithub.com/go-signet/sdk-go/bearerauthv1.1.0.The example demonstrates:
net/httpadapter aroundbearerauth.Verifier.The root README now distinguishes this mixed-credential example from the
JWT-only and all-online resource-server examples.
Related issues
Architecture / flow
flowchart TD C["New client<br/>client/main.go"] -->|"GET + Authorization: Bearer"| A["New HTTP adapter<br/>server/main.go"] A -->|"Raw credential only"| V["sdk-go/bearerauth v1.1.0"] V -->|"JWT"| J["OIDC discovery and lazy JWKS verification"] V -->|"sgk_ Personal API Key"| P["Online tokeninfo or introspection"] J --> I["New normalized identity context"] P --> I I --> R["New /api/whoami JSON response"] V -->|"Typed verification error"| E["New 401 / 403 / 503 / 500 mapping"] style C fill:#dff0d8,stroke:#3c763d,color:#1d3b1d style A fill:#dff0d8,stroke:#3c763d,color:#1d3b1d style I fill:#dff0d8,stroke:#3c763d,color:#1d3b1d style R fill:#dff0d8,stroke:#3c763d,color:#1d3b1d style E fill:#dff0d8,stroke:#3c763d,color:#1d3b1d style V fill:#f5f5f5,stroke:#777,color:#222 style J fill:#f5f5f5,stroke:#777,color:#222 style P fill:#f5f5f5,stroke:#777,color:#222AI authorship
README.md,plan.md, andgo-bearerauth/**README.md,plan.md, andgo-bearerauth/**Change classification
This is classified as Core because it demonstrates authentication policy,
credential handling, and an external HTTP authentication interface.
Plan reference
plan.mdrecords the approved goal, scope boundaries, implementation design,verification strategy, risks, and rollback plan.
Verification
go mod tidy -diff— passedgo mod verify— passedtest -z "$(gofmt -l client/*.go server/*.go)"— passedgo vet ./...— passedgo test -race -count=1 ./...— passedgo test -count=10 ./...— passedGOSUMDB=sum.golang.org GOTOOLCHAIN=go1.25.10 go test -count=1 ./...— passedgo test -cover -count=1 ./...— client 83.3%, server 80.5%go build ./...— passedgit diff --checkandgit diff --staged --check— passedSecurity check
Risk and rollback
307df54623a8.Reviewer guide
go-bearerauth/server/main.go: verifier construction, header parsing, identity propagation, and error mapping.go-bearerauth/client/main.go: credential redaction, URL validation, redirect refusal, and bounded responses.go-bearerauth/README.md: SDK behavior, tokeninfo/introspection guidance, and security claims..env.example, module dependency pin, root README, and implementation plan.