1e5dfa5193
Fase 4 del issue 0010 — cliente OAuth2 sin golang.org/x/oauth2. - Oauth2AuthURL es pura: solo construye la URL con net/url - Oauth2Exchange/Refresh hacen POST application/x-www-form-urlencoded - ExpiresAt calculado como now + expires_in del proveedor - Refresh conserva el token original si el proveedor no devuelve uno nuevo - Tests con httptest.NewServer como mock del proveedor
28 lines
712 B
Go
28 lines
712 B
Go
package infra
|
|
|
|
import (
|
|
"net/url"
|
|
"strings"
|
|
)
|
|
|
|
// Oauth2AuthURL construye la URL de autorizacion OAuth2 a partir de la config.
|
|
// Funcion pura — no hace I/O, solo concatenacion de strings.
|
|
// La URL resultante redirige al usuario al proveedor para que autorice el acceso.
|
|
func Oauth2AuthURL(config OAuthConfig, state string) string {
|
|
q := url.Values{}
|
|
q.Set("client_id", config.ClientID)
|
|
q.Set("redirect_uri", config.RedirectURL)
|
|
q.Set("response_type", "code")
|
|
if len(config.Scopes) > 0 {
|
|
q.Set("scope", strings.Join(config.Scopes, " "))
|
|
}
|
|
if state != "" {
|
|
q.Set("state", state)
|
|
}
|
|
sep := "?"
|
|
if strings.Contains(config.AuthURL, "?") {
|
|
sep = "&"
|
|
}
|
|
return config.AuthURL + sep + q.Encode()
|
|
}
|