feat: oauth2_auth_url (pure), oauth2_exchange, oauth2_refresh
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
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
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()
|
||||
}
|
||||
Reference in New Issue
Block a user