Skip to content

feat(auth): restrict AUTHORIZED listener payload to {key, serviceInfo?} (3.5.0)#69

Merged
perki merged 2 commits into
masterfrom
feat/auth-flow-key-only
Jun 1, 2026
Merged

feat(auth): restrict AUTHORIZED listener payload to {key, serviceInfo?} (3.5.0)#69
perki merged 2 commits into
masterfrom
feat/auth-flow-key-only

Conversation

@perki

@perki perki commented Jun 1, 2026

Copy link
Copy Markdown
Member

Summary

Narrows the auth-flow result surface exposed to calling apps and adds pryv.connectFromKey(key, serviceInfoUrl) as the new path from a polling key to a working Connection.

  • onStateChange(state) on the terminal AUTHORIZED state reached through a fresh auth-flow poll now receives only { status, id, key, serviceInfo? }. username / token / apiEndpoint stay inside the lib.
  • Cookie-autologin AUTHORIZED states (no fresh key available, restored from cookie) pass through unchanged so existing pages that build a Connection on page reload keep working.
  • New pryv.connectFromKey(key, serviceInfoUrl, serviceCustomizations?) + Service#connectFromKey(key) helpers.
  • examples/cli-login.js — headless polling pattern reference (Node-only), pairs with app-web-auth3's new ?cli=1 query flag.
  • Version: pryv@3.5.0 + lockstep @pryv/monitor@3.5.0 + @pryv/socket.io@3.5.0. @pryv/cmc unchanged.

Commits

  1. c187ca7 — examples: headless polling-flow sample for CLI callers
  2. 411eab6 — restrict AUTHORIZED listener payload to {key, serviceInfo?} (3.5.0)

Test plan

  • just lint — clean
  • just test all — 276 passing, 2 pending (pryv 182, monitor 24, socket.io 10, cmc 60)
  • New tests: [AFLA]/[AFLB]/[AFLC] (listener filter behaviour) + [CFKA]/[CFKB] (Service#connectFromKey validation)
  • Browser examples (index.html / socket.io.html / monitor.html) updated to support both fresh-key and autologin paths
  • Coordinated server-side change in pryv/open-pryv.io (PR linked below) — needs to land in lockstep
  • Coordinated UI change in pryv/app-web-auth3 (PR linked below) — handles the new ?cli=1 flag + alignment fixes

Coordinated release

This PR is one of three that ship together for the auth-flow surface narrowing:

  • pryv/open-pryv.io#... — server-side response-shape trim
  • pryv/app-web-auth3#... — auth UI alignment + ?cli=1

See CHANGELOG.md § [3.5.0] for the migration recipe.

perki added 2 commits June 1, 2026 15:34
Demonstrates how a non-browser caller (CLI, daemon, bot) can drive
the access-request flow using the existing `Service.startAccessRequest`
+ `Service.pollAccessRequest` methods. Pattern reference; no new
public API.

The sample appends `cli=1` to the auth URL so the auth UI knows to
render a terminal "you can close this window" screen on success
instead of trying to close a popup or redirect.
The calling app's `onStateChange` callback, when reached through a fresh
auth-flow poll → ACCEPTED, now receives only
`{ status, id, key, serviceInfo? }`. Credentials (`username`, `token`,
`apiEndpoint`) stay inside the lib.

To obtain a working `Connection` from the result, use the new
`pryv.connectFromKey(key, serviceInfoUrl)` (or
`service.connectFromKey(key)`) helper.

Cookie-autologin AUTHORIZED states (no fresh key available) pass
through unchanged so existing pages that build a Connection on page
reload keep working.

Surface changes:
- `Service#connectFromKey(key)` and `pryv.connectFromKey(key, url, ?customizations)` added.
- `AuthController` remembers the polling key from the initial access
  POST and attaches it back onto the terminal AUTHORIZED state, since
  the server's poll response doesn't echo `key` back.
- The external `onStateChange` listener is wrapped in a filter at
  registration time; internal listeners (LoginButton's cookie/autologin
  path) keep seeing the full state.
- Browser examples (index/socket.io/monitor) updated to support both
  fresh-key and autologin paths.
- New `examples/cli-login.js` pairs with the auth UI's `?cli=1` flag
  for headless polling from Node.

Tests: +5 ([AFLA/B/C] listener filter + [CFKA/B] connectFromKey
validation). Lib-js full suite: 276 passing, 2 pending.

Version: `pryv@3.5.0` (lockstep `@pryv/monitor@3.5.0` +
`@pryv/socket.io@3.5.0`; `@pryv/cmc` unchanged). Minor bump — the new
`connectFromKey` helper is additive; the listener-payload narrowing
applies only to fresh auth-flow callbacks and consumers that read
`state.apiEndpoint` migrate per the CHANGELOG recipe.
@perki perki marked this pull request as ready for review June 1, 2026 14:55
@codecov

codecov Bot commented Jun 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.30841% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.24%. Comparing base (e0b13ea) to head (411eab6).

Files with missing lines Patch % Lines
components/pryv/src/Auth/AuthController.js 81.63% 9 Missing ⚠️
components/pryv/src/Service.js 82.35% 6 Missing ⚠️
components/pryv/src/index.js 79.16% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #69      +/-   ##
==========================================
- Coverage   92.50%   92.24%   -0.26%     
==========================================
  Files          32       32              
  Lines        4656     4760     +104     
==========================================
+ Hits         4307     4391      +84     
- Misses        349      369      +20     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@perki perki merged commit ee468da into master Jun 1, 2026
1 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant