Files
fn_registry/functions/infra/oauth2_auth_url.md
T
egutierrez cfdf515228 chore: auto-commit (799 archivos)
- .claude/CLAUDE.md
- .claude/commands/subagentes.md
- .claude/rules/INDEX.md
- .mcp.json
- bash/functions/cybersecurity/analyze_dns.md
- bash/functions/cybersecurity/audit_http_headers.md
- bash/functions/cybersecurity/audit_ssh_config.md
- bash/functions/cybersecurity/check_firewall.md
- bash/functions/cybersecurity/detect_suspicious_users.md
- bash/functions/cybersecurity/encrypt_file.md
- ...

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-14 00:28:20 +02:00

2.0 KiB

name, kind, lang, domain, version, purity, signature, description, tags, uses_functions, uses_types, returns, returns_optional, error_type, imports, params, output, tested, tests, test_file_path, file_path
name kind lang domain version purity signature description tags uses_functions uses_types returns returns_optional error_type imports params output tested tests test_file_path file_path
oauth2_auth_url function go infra 1.0.0 pure func Oauth2AuthURL(config OAuthConfig, state string) string Construye la URL de autorizacion OAuth2 a partir de la config. Funcion pura que concatena el AuthURL del proveedor con los query params (client_id, redirect_uri, response_type=code, scope, state).
oauth
oauth2
auth
url
infra
pendiente-usar
OAuthConfig_go_infra
false
net/url
strings
name desc
config OAuthConfig del proveedor (Google, GitHub, etc.) con ClientID, AuthURL, RedirectURL y Scopes
name desc
state valor aleatorio anti-CSRF que debe validarse en el callback. Si es vacio no se añade
URL completa a la que redirigir al usuario para iniciar el flujo OAuth2 true
genera URL con todos los params basicos
concatena scopes con espacio
añade state si no es vacio
detecta si AuthURL ya trae query y usa & en vez de ?
functions/infra/oauth2_auth_url_test.go functions/infra/oauth2_auth_url.go

Ejemplo

google := OAuthConfig{
    ClientID:    os.Getenv("GOOGLE_CLIENT_ID"),
    AuthURL:     "https://accounts.google.com/o/oauth2/v2/auth",
    RedirectURL: "http://localhost:8080/callback",
    Scopes:      []string{"openid", "email", "profile"},
}
state := "random-anti-csrf-token" // guardar en cookie/session
url := Oauth2AuthURL(google, state)
http.Redirect(w, r, url, http.StatusTemporaryRedirect)

Notas

Pura — solo hace string building con net/url.Values.Encode() (ordena params alfabeticamente y hace URL-encoding). No lee env, ni toca I/O, ni time.Now(). El state es critico para prevenir CSRF: debe ser aleatorio por sesion, guardarse server-side (cookie firmada, session, etc.) y validarse en el callback antes de hacer Oauth2Exchange. Un state vacio significa sin proteccion CSRF y no se incluye en la URL — solo apto para pruebas locales.