feat(yaiam): web sign-in at any OIDC provider behind another name

Web.PublicIssuer sends the browser to the provider's endpoints on a
public origin while the server keeps Issuer (container networks); the
callback's iss may name either. Client.AllowInsecure accepts plain http
off loopback for test installations on a closed network. email_verified
counts only as the JSON boolean true; a string no longer fails the
sign-in. First consumer: yaemp.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
terminarandClaude Opus 5.5 committed 2026-11-20 17:32:32 +01:00
1 parent 538a6c8ae6
commit 376ae3c970
8 files changed
+159 -17

No files matched your search

+12 -6
View File
@@ -92,6 +92,12 @@ type Client struct {
// TLS certificates: a web sign-in trusts the ID token because it
// comes from the token endpoint over TLS.
HTTPClient *http.Client
// AllowInsecure accepts plain http on any host, not only on loopback:
// for a test installation whose provider sits on a closed network
// (e.g. a compose network, "http://oidc:8080/default"). Without TLS a
// web sign-in's ID token is only as trustworthy as that network --
// never set it for a provider reached over the internet.
AllowInsecure bool
mu sync.Mutex
meta *metadata
@@ -136,7 +142,7 @@ func (c *Client) discover(ctx context.Context) (*metadata, error) {
if m != nil {
return m, nil
}
if err := checkURL("issuer", c.Issuer); err != nil {
if err := checkURL("issuer", c.Issuer, c.AllowInsecure); err != nil {
return nil, err
}
if c.ClientID == "" {
@@ -161,7 +167,7 @@ func (c *Client) discover(ctx context.Context) (*metadata, error) {
if m.Issuer != c.Issuer {
return nil, fmt.Errorf("yaiam: discovery names the issuer %q, not %q", m.Issuer, c.Issuer)
}
if err := checkURL("token_endpoint", m.TokenEndpoint); err != nil {
if err := checkURL("token_endpoint", m.TokenEndpoint, c.AllowInsecure); err != nil {
return nil, err
}
// The others only where a flow needs them (device: StartDevice; web:
@@ -170,7 +176,7 @@ func (c *Client) discover(ctx context.Context) (*metadata, error) {
"device_authorization_endpoint": m.DeviceAuthorizationEndpoint, "authorization_endpoint": m.AuthorizationEndpoint,
"end_session_endpoint": m.EndSessionEndpoint} {
if u != "" {
if err := checkURL(name, u); err != nil {
if err := checkURL(name, u, c.AllowInsecure); err != nil {
return nil, err
}
}
@@ -182,8 +188,8 @@ func (c *Client) discover(ctx context.Context) (*metadata, error) {
}
// checkURL refuses anything but an absolute https URL, or http on a
// loopback host.
func checkURL(name, s string) error {
// loopback host (any host with insecure).
func checkURL(name, s string, insecure bool) error {
u, err := url.Parse(s)
if err != nil || u.Host == "" {
return fmt.Errorf("yaiam: %s %q is not an absolute URL", name, s)
@@ -191,7 +197,7 @@ func checkURL(name, s string) error {
switch {
case u.Scheme == "https":
return nil
case u.Scheme == "http" && isLoopback(u.Hostname()):
case u.Scheme == "http" && (insecure || isLoopback(u.Hostname())):
return nil
}
return fmt.Errorf("yaiam: %s %q is not https", name, s)