yaiam: web sign-in (Web) and admin API reads (Admin)

Web signs the users of a web application in with the code flow and
PKCE: state, nonce and verifier in a short-lived __Host- cookie, the ID
token checked per OIDC Core 3.1.3.7, profile, groups and roles from
UserInfo, and the RP-initiated logout URL. Admin reads users, groups
and group members from yaiam's admin API with a client credentials
token. Toolchain go1.27.4.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
terminarandClaude Opus 5.5 committed 2026-11-17 10:54:53 +01:00
1 parent 4bff8798e5
commit a3e8f9bb3b
10 files changed
+1183 -16

No files matched your search

+19 -8
View File
@@ -88,7 +88,9 @@ type Client struct {
// again once the access token runs out.
Scopes []string
// HTTPClient sends the requests; nil means one with a 30 s timeout.
// Redirects are never followed, whichever client it is.
// Redirects are never followed, whichever client it is. It must check
// TLS certificates: a web sign-in trusts the ID token because it
// comes from the token endpoint over TLS.
HTTPClient *http.Client
mu sync.Mutex
@@ -103,6 +105,8 @@ type metadata struct {
DeviceAuthorizationEndpoint string `json:"device_authorization_endpoint"`
RevocationEndpoint string `json:"revocation_endpoint"`
UserinfoEndpoint string `json:"userinfo_endpoint"`
AuthorizationEndpoint string `json:"authorization_endpoint"`
EndSessionEndpoint string `json:"end_session_endpoint"`
}
// httpClient is HTTPClient (or the default) without redirects: an answer
@@ -157,12 +161,14 @@ 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)
}
for name, u := range map[string]string{"token_endpoint": m.TokenEndpoint, "device_authorization_endpoint": m.DeviceAuthorizationEndpoint} {
if err := checkURL(name, u); err != nil {
return nil, err
}
if err := checkURL("token_endpoint", m.TokenEndpoint); err != nil {
return nil, err
}
for name, u := range map[string]string{"revocation_endpoint": m.RevocationEndpoint, "userinfo_endpoint": m.UserinfoEndpoint} {
// The others only where a flow needs them (device: StartDevice; web:
// Web.SignIn); those that are named must be https.
for name, u := range map[string]string{"revocation_endpoint": m.RevocationEndpoint, "userinfo_endpoint": m.UserinfoEndpoint,
"device_authorization_endpoint": m.DeviceAuthorizationEndpoint, "authorization_endpoint": m.AuthorizationEndpoint,
"end_session_endpoint": m.EndSessionEndpoint} {
if u != "" {
if err := checkURL(name, u); err != nil {
return nil, err
@@ -201,16 +207,21 @@ func isLoopback(host string) bool {
// do sends req and reads at most maxBody of the answer.
func (c *Client) do(req *http.Request) (int, []byte, error) {
return c.doMax(req, maxBody)
}
// doMax is do with another limit.
func (c *Client) doMax(req *http.Request, limit int64) (int, []byte, error) {
resp, err := c.httpClient().Do(req)
if err != nil {
return 0, nil, err
}
defer resp.Body.Close()
body, err := io.ReadAll(io.LimitReader(resp.Body, maxBody+1))
body, err := io.ReadAll(io.LimitReader(resp.Body, limit+1))
if err != nil {
return 0, nil, err
}
if len(body) > maxBody {
if int64(len(body)) > limit {
return 0, nil, errors.New("answer too large")
}
return resp.StatusCode, body, nil