Ejemplo
cloud.google.com/go/auth v0.18.2: AuthorizationHandlerOptions
Muestra verificada para golang cloud.google.com/go/auth v0.18.2: AuthorizationHandlerOptions. El contrato se ejecutó en go 1.26 · linux debian/x64 · docker y…
sha256:4d7057ca37504bdd1015c8c3c39f5d89dfb6f1f4b9e37f79670f75ebbf69ada3
Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido.
Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas.
MIT-0
Evidencia de ejecución
El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.
- Base de evidencia
- Contrato firmado aprobado
- Recibos de verificación
- 1
- Claves de firma que lo compilaron
- 1
Entorno declarado
linux 24 · ubuntu · glibc 2.39 x64 go
Entornos de las ejecuciones de verificación
| Entorno | Contrato | Etapas | Ejecución |
|---|---|---|---|
| go 1.26 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a… |
2026-10-11 |
Caso
HOW- Objetivo
- verify cloud.google.com/go/auth.AuthorizationHandlerOptions in pkg:golang/cloud.google.com/go/auth@v0.18.2
- Paquetes
- Símbolos
-
- cloud.google.com/go/auth.AuthorizationHandlerOptions
- Creado
- 2026-10-11T06:43:38Z
Contrato
- New3LOTokenProvider accepts AuthorizationHandlerOptions without requiring ClientSecret or RefreshToken
- TokenProvider executes custom AuthorizationHandler with constructed authorization code URL and state
- TokenProvider validates state parameter and rejects mismatch between handler response and configured state
- AuthorizationHandlerOptions supports PKCE configurations appending challenge to authorization URL and verifier to token exchange
- TokenProvider exchanges authorization code successfully and returns valid auth.Token
Archivos
- PROMPT.md
- auth_handler.go
- csx.json
- go.mod
- go.sum
- spec.json
- test/contract.go
Código fuente
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify cloud.google.com/go/auth.AuthorizationHandlerOptions in pkg:golang/cloud.google.com/go/auth@v0.18.2
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/cloud.google.com/go/auth@v0.18.2
Demonstrate these symbols/APIs:
- cloud.google.com/go/auth.AuthorizationHandlerOptions
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
package sample
import (
"context"
"net/http"
"cloud.google.com/go/auth"
)
// Config holds options for configuring a 3-legged OAuth flow with custom handler options.
type Config struct {
ClientID string
AuthURL string
TokenURL string
State string
Handler auth.AuthorizationHandler
PKCEOpts *auth.PKCEOptions
HTTPClient *http.Client
}
// NewTokenProviderWithHandler creates a TokenProvider configured with AuthorizationHandlerOptions.
func NewTokenProviderWithHandler(cfg Config) (auth.TokenProvider, error) {
opts := &auth.Options3LO{
ClientID: cfg.ClientID,
AuthURL: cfg.AuthURL,
TokenURL: cfg.TokenURL,
AuthStyle: auth.StyleInParams,
Client: cfg.HTTPClient,
AuthHandlerOpts: &auth.AuthorizationHandlerOptions{
Handler: cfg.Handler,
State: cfg.State,
PKCEOpts: cfg.PKCEOpts,
},
}
return auth.New3LOTokenProvider(opts)
}
// FetchToken retrieves an access token using the provided TokenProvider.
func FetchToken(ctx context.Context, tp auth.TokenProvider) (*auth.Token, error) {
return tp.Token(ctx)
}
{"case":{"caseId":"case:sha256:3fa7589976469a5ff001ce8ef8be2fee8787d4329f3c1282ff3278d0bfd06179","contract":["New3LOTokenProvider accepts AuthorizationHandlerOptions without requiring ClientSecret or RefreshToken","TokenProvider executes custom AuthorizationHandler with constructed authorization code URL and state","TokenProvider validates state parameter and rejects mismatch between handler response and configured state","AuthorizationHandlerOptions supports PKCE configurations appending challenge to authorization URL and verifier to token exchange","TokenProvider exchanges authorization code successfully and returns valid auth.Token"],"goal":"verify cloud.google.com/go/auth.AuthorizationHandlerOptions in pkg:golang/cloud.google.com/go/auth@v0.18.2","kind":"HOW","packages":["pkg:golang/cloud.google.com/go/auth@v0.18.2"],"schemaVersion":1,"symbols":["cloud.google.com/go/auth.AuthorizationHandlerOptions"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/cloud.google.com/go/auth@v0.18.2"],"schemaVersion":1,"subject":"pkg:golang/cloud.google.com/go/auth@v0.18.2","symbols":["cloud.google.com/go/auth.AuthorizationHandlerOptions"],"verifierAdapter":"golang@1"}
module sample
go 1.24.0
require cloud.google.com/go/auth v0.18.2
require (
cloud.google.com/go/compute/metadata v0.9.0 // indirect
github.com/googleapis/gax-go/v2 v2.17.0 // indirect
golang.org/x/sys v0.40.0 // indirect
)
cloud.google.com/go/auth v0.18.2 h1:+Nbt5Ev0xEqxlNjd6c+yYUeosQ5TtEUaNcN/3FozlaM=
cloud.google.com/go/auth v0.18.2/go.mod h1:xD+oY7gcahcu7G2SG2DsBerfFxgPAJz17zz2joOFF3M=
cloud.google.com/go/compute/metadata v0.9.0 h1:pDUj4QMoPejqq20dK0Pg2N4yG9zIkYGdBtwLoEkH9Zs=
cloud.google.com/go/compute/metadata v0.9.0/go.mod h1:E0bWwX5wTnLPedCKqk3pJmVgCBSM6qQI1yTBdEb3C10=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/s2a-go v0.1.9 h1:LGD7gtMgezd8a/Xak7mEWL0PjoTQFvpRudN895yqKW0=
github.com/google/s2a-go v0.1.9/go.mod h1:YA0Ei2ZQL3acow2O62kdp9UlnvMmU7kA6Eutn0dXayM=
github.com/googleapis/enterprise-certificate-proxy v0.3.11 h1:vAe81Msw+8tKUxi2Dqh/NZMz7475yUvmRIkXr4oN2ao=
github.com/googleapis/enterprise-certificate-proxy v0.3.11/go.mod h1:RFV7MUdlb7AgEq2v7FmMCfeSMCllAzWxFgRdusoGks8=
github.com/googleapis/gax-go/v2 v2.17.0 h1:RksgfBpxqff0EZkDWYuz9q/uWsTVz+kf43LsZ1J6SMc=
github.com/googleapis/gax-go/v2 v2.17.0/go.mod h1:mzaqghpQp4JDh3HvADwrat+6M3MOIDp5YKHhb9PAgDY=
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.61.0 h1:F7Jx+6hwnZ41NSFTO5q4LYDtJRXBf2PD0rNBkeB/lus=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.61.0/go.mod h1:UHB22Z8QsdRDrnAtX4PntOl36ajSxcdUMt1sF7Y6E7Q=
go.opentelemetry.io/otel v1.39.0 h1:8yPrr/S0ND9QEfTfdP9V+SiwT4E0G7Y5MO7p85nis48=
go.opentelemetry.io/otel v1.39.0/go.mod h1:kLlFTywNWrFyEdH0oj2xK0bFYZtHRYUdv1NklR/tgc8=
go.opentelemetry.io/otel/metric v1.39.0 h1:d1UzonvEZriVfpNKEVmHXbdf909uGTOQjA0HF0Ls5Q0=
go.opentelemetry.io/otel/metric v1.39.0/go.mod h1:jrZSWL33sD7bBxg1xjrqyDjnuzTUB0x1nBERXd7Ftcs=
go.opentelemetry.io/otel/trace v1.39.0 h1:2d2vfpEDmCJ5zVYz7ijaJdOF59xLomrvj7bjt6/qCJI=
go.opentelemetry.io/otel/trace v1.39.0/go.mod h1:88w4/PnZSazkGzz/w84VHpQafiU4EtqqlVdxWy+rNOA=
golang.org/x/crypto v0.47.0 h1:V6e3FRj+n4dbpw86FJ8Fv7XVOql7TEwpHapKoMJ/GO8=
golang.org/x/crypto v0.47.0/go.mod h1:ff3Y9VzzKbwSSEzWqJsJVBnWmRwRSHt/6Op5n9bQc4A=
golang.org/x/net v0.49.0 h1:eeHFmOGUTtaaPSGNmjBKpbng9MulQsJURQUAfUwY++o=
golang.org/x/net v0.49.0/go.mod h1:/ysNB2EvaqvesRkuLAyjI1ycPZlQHM3q01F02UY/MV8=
golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ=
golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/text v0.33.0 h1:B3njUFyqtHDUI5jMn1YIr5B0IE2U0qck04r6d4KPAxE=
golang.org/x/text v0.33.0/go.mod h1:LuMebE6+rBincTi9+xWTY8TztLzKHc/9C1uBCG27+q8=
google.golang.org/genproto v0.0.0-20260128011058-8636f8732409 h1:VQZ/yAbAtjkHgH80teYd2em3xtIkkHd7ZhqfH2N9CsM=
google.golang.org/genproto/googleapis/rpc v0.0.0-20260128011058-8636f8732409 h1:H86B94AW+VfJWDqFeEbBPhEtHzJwJfTbgE2lZa54ZAQ=
google.golang.org/genproto/googleapis/rpc v0.0.0-20260128011058-8636f8732409/go.mod h1:j9x/tPzZkyxcgEFkiKEEGxfvyumM01BEtsW8xzOahRQ=
google.golang.org/grpc v1.78.0 h1:K1XZG/yGDJnzMdd/uZHAkVqJE+xIDOcmdSFZkBUicNc=
google.golang.org/grpc v1.78.0/go.mod h1:I47qjTo4OKbMkjA/aOOwxDIiPSBofUtQUI5EfpWvW7U=
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
{
"schemaVersion": 1,
"goal": "verify cloud.google.com/go/auth.AuthorizationHandlerOptions in pkg:golang/cloud.google.com/go/auth@v0.18.2",
"kind": "HOW",
"packages": [
"pkg:golang/cloud.google.com/go/auth@v0.18.2"
],
"symbols": [
"cloud.google.com/go/auth.AuthorizationHandlerOptions"
]
}
package main
import (
"context"
"fmt"
"net/http"
"net/http/httptest"
"os"
"strings"
"sync/atomic"
"cloud.google.com/go/auth"
"sample"
)
func main() {
// Assertion 1: New3LOTokenProvider accepts AuthorizationHandlerOptions without requiring ClientSecret or RefreshToken
stdOpts := &auth.Options3LO{
ClientID: "test-client-id",
AuthURL: "http://localhost/auth",
TokenURL: "http://localhost/token",
AuthStyle: auth.StyleInParams,
}
if _, err := auth.New3LOTokenProvider(stdOpts); err == nil {
fmt.Fprintf(os.Stderr, "FAIL: expected validation error when ClientSecret/RefreshToken missing without AuthHandlerOpts\n")
os.Exit(1)
}
handlerOpts := sample.Config{
ClientID: "test-client-id",
AuthURL: "http://localhost/auth",
TokenURL: "http://localhost/token",
State: "state-123",
Handler: func(authCodeURL string) (string, string, error) {
return "code-abc", "state-123", nil
},
}
tp1, err := sample.NewTokenProviderWithHandler(handlerOpts)
if err != nil || tp1 == nil {
fmt.Fprintf(os.Stderr, "FAIL: NewTokenProviderWithHandler failed: %v\n", err)
os.Exit(1)
}
// Assertion 2: TokenProvider executes custom AuthorizationHandler with constructed authorization code URL and state
var capturedAuthURL string
var handlerCalled atomic.Bool
server2 := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.Write([]byte(`{"access_token":"token-2","token_type":"bearer","expires_in":3600}`))
}))
defer server2.Close()
tp2, err := sample.NewTokenProviderWithHandler(sample.Config{
ClientID: "client-id-xyz",
AuthURL: "http://localhost/oauth/authorize",
TokenURL: server2.URL,
State: "unique-state-456",
HTTPClient: server2.Client(),
Handler: func(authCodeURL string) (string, string, error) {
capturedAuthURL = authCodeURL
handlerCalled.Store(true)
return "code-xyz", "unique-state-456", nil
},
})
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: failed to create tp2: %v\n", err)
os.Exit(1)
}
_, err = sample.FetchToken(context.Background(), tp2)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: tp2 FetchToken failed: %v\n", err)
os.Exit(1)
}
if !handlerCalled.Load() {
fmt.Fprintf(os.Stderr, "FAIL: AuthorizationHandler was not called\n")
os.Exit(1)
}
if !strings.Contains(capturedAuthURL, "client_id=client-id-xyz") ||
!strings.Contains(capturedAuthURL, "state=unique-state-456") ||
!strings.Contains(capturedAuthURL, "response_type=code") {
fmt.Fprintf(os.Stderr, "FAIL: capturedAuthURL missing expected parameters: %s\n", capturedAuthURL)
os.Exit(1)
}
// Assertion 3: TokenProvider validates state parameter and rejects mismatch between handler response and configured state
tp3, err := sample.NewTokenProviderWithHandler(sample.Config{
ClientID: "client-id-3",
AuthURL: "http://localhost/oauth/authorize",
TokenURL: "http://localhost/token",
State: "expected-state",
Handler: func(authCodeURL string) (string, string, error) {
return "some-code", "tampered-state", nil
},
})
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: failed to create tp3: %v\n", err)
os.Exit(1)
}
_, err = sample.FetchToken(context.Background(), tp3)
if err == nil || !strings.Contains(err.Error(), "state mismatch") {
fmt.Fprintf(os.Stderr, "FAIL: expected state mismatch error, got: %v\n", err)
os.Exit(1)
}
// Assertion 4: AuthorizationHandlerOptions supports PKCE configurations appending challenge to authorization URL and verifier to token exchange
var pkceCapturedURL string
var verifierReceived string
server4 := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
verifierReceived = r.Form.Get("code_verifier")
w.Header().Set("Content-Type", "application/json")
w.Write([]byte(`{"access_token":"token-pkce","token_type":"bearer","expires_in":3600}`))
}))
defer server4.Close()
tp4, err := sample.NewTokenProviderWithHandler(sample.Config{
ClientID: "client-pkce",
AuthURL: "http://localhost/oauth/authorize",
TokenURL: server4.URL,
State: "state-pkce",
HTTPClient: server4.Client(),
PKCEOpts: &auth.PKCEOptions{
Challenge: "challenge-string",
ChallengeMethod: "S256",
Verifier: "verifier-secret",
},
Handler: func(authCodeURL string) (string, string, error) {
pkceCapturedURL = authCodeURL
return "auth-code-pkce", "state-pkce", nil
},
})
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: failed to create tp4: %v\n", err)
os.Exit(1)
}
_, err = sample.FetchToken(context.Background(), tp4)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: tp4 FetchToken failed: %v\n", err)
os.Exit(1)
}
if !strings.Contains(pkceCapturedURL, "code_challenge=challenge-string") ||
!strings.Contains(pkceCapturedURL, "code_challenge_method=S256") {
fmt.Fprintf(os.Stderr, "FAIL: PKCE challenge parameters missing in authURL: %s\n", pkceCapturedURL)
os.Exit(1)
}
if verifierReceived != "verifier-secret" {
fmt.Fprintf(os.Stderr, "FAIL: expected code_verifier 'verifier-secret', got '%s'\n", verifierReceived)
os.Exit(1)
}
// Assertion 5: TokenProvider exchanges authorization code successfully and returns valid auth.Token
server5 := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
if r.Form.Get("grant_type") != "authorization_code" || r.Form.Get("code") != "valid-code-5" {
http.Error(w, "invalid request", http.StatusBadRequest)
return
}
w.Header().Set("Content-Type", "application/json")
w.Write([]byte(`{
"access_token": "valid-token-5",
"token_type": "bearer",
"expires_in": 7200
}`))
}))
defer server5.Close()
tp5, err := sample.NewTokenProviderWithHandler(sample.Config{
ClientID: "client-5",
AuthURL: "http://localhost/oauth/authorize",
TokenURL: server5.URL,
State: "state-5",
HTTPClient: server5.Client(),
Handler: func(authCodeURL string) (string, string, error) {
return "valid-code-5", "state-5", nil
},
})
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: failed to create tp5: %v\n", err)
os.Exit(1)
}
tok5, err := sample.FetchToken(context.Background(), tp5)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: tp5 FetchToken failed: %v\n", err)
os.Exit(1)
}
if tok5 == nil || !tok5.IsValid() {
fmt.Fprintf(os.Stderr, "FAIL: expected valid token, got: %v\n", tok5)
os.Exit(1)
}
if tok5.Value != "valid-token-5" {
fmt.Fprintf(os.Stderr, "FAIL: expected token value 'valid-token-5', got '%s'\n", tok5.Value)
os.Exit(1)
}
if tok5.Type != "bearer" {
fmt.Fprintf(os.Stderr, "FAIL: expected token type 'bearer', got '%s'\n", tok5.Type)
os.Exit(1)
}
if tok5.Expiry.IsZero() {
fmt.Fprintf(os.Stderr, "FAIL: expected non-zero token expiry\n")
os.Exit(1)
}
fmt.Println("PASS: cloud.google.com/go/auth.AuthorizationHandlerOptions verified")
}
Seeder de origen
anónimo