From f9746185885df4a3a7972e4cfcb599d2adb57487 Mon Sep 17 00:00:00 2001 From: "Daniel P. Clark" <6ftdan@gmail.com> Date: Wed, 21 Oct 2026 04:45:16 +0000 Subject: [PATCH] Bring every document up to date with the 0.1.1 code Corrects drift across the root README, the integration guides, the gem READMEs and the example READMEs: the Roda plugin, the refresh endpoint, the store implementations, the hooks and host allow-list, account policies and identity management, the client's TLS and insecure flags, and a "logging in with the browser extension" section per example. Deferred work is now pointed at GitHub issues. The release_check task compares the tag with the version when run in CI. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_01LquamEUPHNaNMzZW6tZz8r --- README.md | 33 ++++++++++++++++------ Rakefile | 6 +++- docs/integrations/README.md | 28 ++++++++++++------ docs/integrations/client.md | 9 ++++-- docs/integrations/devise.md | 21 ++++++++++---- docs/integrations/omniauth.md | 10 +++++-- docs/integrations/rack-sinatra.md | 47 +++++++++++++++++++++++++------ docs/integrations/rails.md | 32 +++++++++++++++++---- examples/devise-app/README.md | 11 ++++++-- examples/omniauth-app/README.md | 14 +++++++-- examples/rack-app/README.md | 20 +++++++++---- examples/rails-auth-app/README.md | 11 ++++++-- examples/roda-app/README.md | 10 ++++++- examples/sinatra-app/README.md | 10 ++++++- gems/devise-sqrl/README.md | 12 ++++++-- gems/omniauth-sqrl/README.md | 7 ++++- gems/sqrl-rack/README.md | 14 +++++---- gems/sqrl-rails/README.md | 5 +++- 18 files changed, 233 insertions(+), 67 deletions(-) diff --git a/README.md b/README.md index bed3353..d05f78f 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ that logs in to SQRL-enabled websites from scripts and test suites. | Gem | Version | Downloads | Require | Use it when | Quick start | | --- | --- | --- | --- | --- | --- | | [`sqrl-core`](gems/sqrl-core) | [![Gem Version](https://img.shields.io/gem/v/sqrl-core?logo=rubygems&logoColor=white)](https://rubygems.org/gems/sqrl-core) | [![Downloads](https://img.shields.io/gem/dt/sqrl-core)](https://rubygems.org/gems/sqrl-core) | `require "sqrl/core"` (or `"sqrl"`) | you need the protocol, the cryptography or the identity formats directly | `SQRL::Session`, `SQRL::Server::Handler`, `SQRL::S4Identity` | -| [`sqrl-rack`](gems/sqrl-rack) | [![Gem Version](https://img.shields.io/gem/v/sqrl-rack?logo=rubygems&logoColor=white)](https://rubygems.org/gems/sqrl-rack) | [![Downloads](https://img.shields.io/gem/dt/sqrl-rack)](https://rubygems.org/gems/sqrl-rack) | `require "sqrl/rack"` | a Rack application or Sinatra | `use SQRL::Rack::Middleware` / `register Sinatra::SQRL` | +| [`sqrl-rack`](gems/sqrl-rack) | [![Gem Version](https://img.shields.io/gem/v/sqrl-rack?logo=rubygems&logoColor=white)](https://rubygems.org/gems/sqrl-rack) | [![Downloads](https://img.shields.io/gem/dt/sqrl-rack)](https://rubygems.org/gems/sqrl-rack) | `require "sqrl/rack"` | Rack, Sinatra or Roda | `use SQRL::Rack::Middleware` / `register Sinatra::SQRL` / `plugin :sqrl` | | [`omniauth-sqrl`](gems/omniauth-sqrl) | [![Gem Version](https://img.shields.io/gem/v/omniauth-sqrl?logo=rubygems&logoColor=white)](https://rubygems.org/gems/omniauth-sqrl) | [![Downloads](https://img.shields.io/gem/dt/omniauth-sqrl)](https://rubygems.org/gems/omniauth-sqrl) | `require "omniauth/sqrl"` | you already use OmniAuth | `provider :sqrl` | | [`sqrl-rails`](gems/sqrl-rails) | [![Gem Version](https://img.shields.io/gem/v/sqrl-rails?logo=rubygems&logoColor=white)](https://rubygems.org/gems/sqrl-rails) | [![Downloads](https://img.shields.io/gem/dt/sqrl-rails)](https://rubygems.org/gems/sqrl-rails) | `require "sqrl/rails"` | Rails, including the Rails 8 `generate authentication` stack | `bin/rails generate sqrl:install` | | [`devise-sqrl`](gems/devise-sqrl) | [![Gem Version](https://img.shields.io/gem/v/devise-sqrl?logo=rubygems&logoColor=white)](https://rubygems.org/gems/devise-sqrl) | [![Downloads](https://img.shields.io/gem/dt/devise-sqrl)](https://rubygems.org/gems/devise-sqrl) | `require "devise/sqrl"` | Devise | `devise :sqrl_authenticatable` | @@ -50,10 +50,15 @@ All six gems share one version and live in this repository. Per-framework guides test vector. Everything is built on Ruby's bundled `openssl` gem; the core has no other runtime dependency. - A server engine whose state sits behind nut, identity and pending-login store interfaces - (in-memory and ActiveRecord implementations), with nut single use, IP matching, browser - session binding and one-time CPS tokens. + (in-memory, Redis, ActiveRecord and `ActiveSupport::Cache` implementations, all checked by + one shared store-contract spec), with nut single use, IP matching, browser session + binding, one-time CPS tokens, rate-limit and prune hooks and host allow-listing. +- Account policies surfaced to applications: `sqrlonly` refuses password login and + `hardlock` refuses password recovery in the Rails 8 and Devise integrations, and users can + list and unlink their SQRL identities. - A browser script (`sqrl.js`) that performs the standard same-device probe on - `localhost:25519` and polls for logins from another device, plus server-side QR codes. + `localhost:25519`, polls for logins from another device and fetches a fresh code when one + expires, plus server-side QR codes. - A bot client with login-page discovery, a cookie-carrying transport, a Capybara helper, a command-line tool and a 23-case conformance suite. @@ -82,13 +87,25 @@ your own server. ```sh bundle install bundle exec rake spec:gems # every gem's specs -bundle exec rake spec:integration # boots each example app and drives it with the bot client and a headless browser -bundle exec rspec spec/interop # the conformance suite against the Rust reference server (needs its binary) +bundle exec rake spec:integration # boots each example app over HTTPS and drives it with the bot client and a headless browser +bundle exec rspec spec/interop # the conformance suite against the Rust reference server +bundle exec rubocop # lint (enforced in CI) +bundle exec rake build # packages the six gems into pkg/; `rake release_check` lists them ``` Each application under [`examples/`](examples) is a complete, independently bundled -application of its framework (`bin/dev` starts it). The integration specs start every one of -them on a free port and run the conformance suite, bot flows and browser flows against it. +application of its framework (`bin/dev` starts it). Run `bundle install` inside each one +before the integration specs: they start every example on a free port with its own bundle +and run the conformance suite, bot flows and browser flows against it, twice (the second +time with `ask` and `sin` enabled). + +What the suites need: a Chromium binary for the browser flows (`BROWSER_PATH`, or the +Playwright Chromium that CI installs), the Rust toolchain and a checkout of +`SQRL-extension` for the interop run (`SQRL_RUST_TEST_SERVER` points at the built +`sqrl-test-server`; the specs skip without it), and optionally a local `redis-server` for +the Redis store specs (they also run against an in-process double). `gemfiles/` holds the +Rails 7.1, 7.2 and 8.0 bundles that CI runs `sqrl-rails` and `devise-sqrl` against. +Deferred work and ideas are tracked as GitHub issues. Ruby 3.1 or newer for `sqrl-core`, `sqrl-rack`, `omniauth-sqrl` and `sqrl-client`; Ruby 3.2 or newer for `sqrl-rails` and `devise-sqrl`. One EnScrypt iteration takes about diff --git a/Rakefile b/Rakefile index 858e1f1..3edae4f 100644 --- a/Rakefile +++ b/Rakefile @@ -40,7 +40,11 @@ task :build do end end -desc "Check that every gem builds cleanly and that the tag would match the version" +desc "Check that every gem builds cleanly and, when GITHUB_REF_NAME is set, that the tag matches SQRL::VERSION" task release_check: :build do Dir["pkg/*.gem"].each { |g| puts "built #{g}" } + tag = ENV.fetch("GITHUB_REF_NAME", nil) + if tag && tag != "v#{SQRL::VERSION}" + abort "tag #{tag} does not match SQRL::VERSION #{SQRL::VERSION}" + end end diff --git a/docs/integrations/README.md b/docs/integrations/README.md index 5f0ea97..5183a17 100644 --- a/docs/integrations/README.md +++ b/docs/integrations/README.md @@ -5,7 +5,7 @@ applications hold runnable code. | Framework | Guide | Gem README | Example application | | --- | --- | --- | --- | -| Rack and Sinatra | [rack-sinatra.md](rack-sinatra.md) | [gems/sqrl-rack](../../gems/sqrl-rack/README.md) | [examples/rack-app](../../examples/rack-app), [examples/sinatra-app](../../examples/sinatra-app) | +| Rack, Sinatra and Roda | [rack-sinatra.md](rack-sinatra.md) | [gems/sqrl-rack](../../gems/sqrl-rack/README.md) | [examples/rack-app](../../examples/rack-app), [examples/sinatra-app](../../examples/sinatra-app), [examples/roda-app](../../examples/roda-app) | | OmniAuth | [omniauth.md](omniauth.md) | [gems/omniauth-sqrl](../../gems/omniauth-sqrl/README.md) | [examples/omniauth-app](../../examples/omniauth-app) | | Rails and Rails 8 Authentication | [rails.md](rails.md) | [gems/sqrl-rails](../../gems/sqrl-rails/README.md) | [examples/rails-auth-app](../../examples/rails-auth-app) | | Devise | [devise.md](devise.md) | [gems/devise-sqrl](../../gems/devise-sqrl/README.md) | [examples/devise-app](../../examples/devise-app) | @@ -25,19 +25,29 @@ applications hold runnable code. 4. Another device: `sqrl.js` polls the cookie-bound status endpoint and, once authenticated, navigates to the callback, which completes that browser's own pending login once. 5. The framework adapter turns the authenticated identity into its own notion of a signed-in - user: a session key (Rack), an auth hash (OmniAuth), `start_new_session_for` (Rails 8), - or `sign_in` (Devise). Unknown identities create an account, link to the signed-in user, - or are refused, according to `on_unknown_identity`. + user: a session key (Rack, Sinatra, Roda), an auth hash (OmniAuth), + `start_new_session_for` (Rails 8), or `sign_in` (Devise). Unknown identities create an + account, link to the signed-in user, or are refused, according to `on_unknown_identity`. + +When a nut expires before the user acts, the page's "Get a new code" button calls the +refresh endpoint and swaps in a fresh URL and QR code without a reload. ## Deployment notes that apply everywhere - Set the public `host` explicitly in production; it is the string identities are derived from, so a change breaks every existing SQRL association. -- Use a persistent, atomic store in production (the ActiveRecord stores from `sqrl-rails`, - or your own implementation of the three interfaces in `SQRL::Server`). The in-memory - stores are for development and tests. +- Use a persistent, atomic store in production: ActiveRecord or `ActiveSupport::Cache` + (`sqrl-rails`), Redis (`SQRL::Server::Redis` in `sqrl-core`), or your own implementation + of the three interfaces in `SQRL::Server`. The in-memory stores are for development and + tests. +- Serve HTTPS. SQRL URLs are always `sqrl://`; plain HTTP exists only as the loopback-only + `insecure_http` testing mode. - The SQRL endpoint is exempt from CSRF protection by design: it is authenticated by signatures. Nothing else is. - Keep `require_ip_match` on. Clients behind a different egress than the browser must send - `noiptest`, which the user has to opt into. -- Prune expired nuts and pending logins (`sqrl:prune` in Rails; `Handler#prune!` elsewhere). + `noiptest`, which the user has to opt into. `poll_requires_ip_match` is a separate, + off-by-default hardening; see [docs/security.md](../security.md) before turning it on. +- Rate-limit the login page and the endpoint (`before_issue` / `before_handle` hooks, + Rails `rate_limit`, or Rack::Attack). +- Prune expired nuts and pending logins: `prune_every` does it opportunistically; + `sqrl:prune` (Rails) or `Handler#prune!` from a scheduler otherwise. diff --git a/docs/integrations/client.md b/docs/integrations/client.md index 521a7af..ac8f7d3 100644 --- a/docs/integrations/client.md +++ b/docs/integrations/client.md @@ -19,8 +19,13 @@ agent.http.get("https://example.com/account") # same cookie jar, already logge tests never need a rescue code or EnScrypt. - `SQRL::Client::Capybara.login(page, identity:)` runs the protocol out of band and then has the browser visit the CPS URL, so the browser session is the one logged in. -- The `sqrl-client` executable exposes the same operations and exports cookies in Netscape - or JSON format for `curl` and friends. +- The `sqrl-client` executable exposes the same operations plus identity management + (`identity create|import|show|export|rekey|change-password|previous`), takes `--alt-id`, + and exports cookies in Netscape or JSON format for `curl` and friends. +- The agent speaks `sqrl://` over HTTPS only. `insecure: true` (CLI `--insecure`) is a + loopback-only testing mode for plain-HTTP sites and `qrl://` links such as the browser + extension's test server; a self-signed development certificate is trusted with + `Transport.new(ca_file:)` (CLI `--ca-file`), and `--no-verify-tls` disables verification. ## Conformance suite diff --git a/docs/integrations/devise.md b/docs/integrations/devise.md index f80b3db..50b98d9 100644 --- a/docs/integrations/devise.md +++ b/docs/integrations/devise.md @@ -17,7 +17,9 @@ bin/rails db:migrate `devise_for :users` then provides `GET /users/sqrl` (a stand-alone login page), `POST /users/sqrl/cli` (the SQRL endpoint, exempt from forgery protection), -`GET /users/sqrl/status`, `GET /users/sqrl/callback` and `GET /users/sqrl/sqrl.js`. +`GET /users/sqrl/status`, `GET /users/sqrl/callback`, `GET /users/sqrl/refresh`, +`GET /users/sqrl/sqrl.js`, and `GET /users/sqrl/identities` with +`DELETE /users/sqrl/identities/:id` for managing linked identities. The generator appends `<%= render "devise/shared/sqrl", resource_name: resource_name %>` to `devise/sessions/new.html.erb`, so the password form and the SQRL block live on the same page. @@ -34,14 +36,23 @@ rememberable and the other Devise hooks therefore behave exactly as for a passwo | Option | Default | Meaning | | --- | --- | --- | -| `config.sqrl_on_unknown_identity` | `:create` | `:create` a resource, `:link` to the signed-in resource, or `:refuse` | -| `config.sqrl_create_resource` | `SQRL::Rails::UserFactory` | `(identity, mapping) -> resource` | +| `config.sqrl_on_unknown_identity` | `nil` (defers to `config.sqrl.on_unknown_identity`, `:create`) | `:create` a resource, `:link` to the signed-in resource, or `:refuse` | +| `config.sqrl_create_resource` | `SQRL::Rails::UserFactory` | `(identity, resource_class) -> resource` | | `config.sqrl_remember_me` | `false` | set the remember-me cookie on SQRL sign-in | | `config.sqrl_login_block` | `{}` | options for the rendered login block | | `config.sqrl_failure_path` | the SQRL login page | where a refused callback redirects | +| `config.sqrl_only_blocked_strategies` | `[:database_authenticatable]` | Warden strategies refused for `sqrlonly` users | -Protocol options (`host`, `require_ip_match`, `ask`, `sin`, stores) come from -`Rails.application.config.sqrl`, exactly as for `sqrl-rails`. +Protocol options (`host`, `insecure_http`, `require_ip_match`, `poll_requires_ip_match`, +`ask`, `sin`, `rate_limit`, hooks, stores) come from `Rails.application.config.sqrl`, +exactly as for `sqrl-rails`. + +## Account policies + +A user whose identity asked for `sqrlonly` can no longer sign in through Devise's password +strategy (`devise.failure.sqrl_only`); one whose identity asked for `hardlock` cannot +request or perform a password reset (`errors.messages.sqrl_hard_locked`). SQRL logins, +remember-me cookies and restored sessions are unaffected. ## Model API diff --git a/docs/integrations/omniauth.md b/docs/integrations/omniauth.md index 1937572..7a0d751 100644 --- a/docs/integrations/omniauth.md +++ b/docs/integrations/omniauth.md @@ -11,8 +11,9 @@ end - `POST /auth/sqrl` (the request phase) renders the login page. OmniAuth 2 requires POST and an authenticity token here: Rails apps get it from `omniauth-rails_csrf_protection`, Sinatra apps render `Rack::Protection::AuthenticityToken.token(session)` in the form. -- `POST /auth/sqrl/cli`, `GET /auth/sqrl/status` and `GET /auth/sqrl/sqrl.js` are served by - the strategy itself (OmniAuth's `other_phase`), so they never reach your controllers. +- `POST /auth/sqrl/cli`, `GET /auth/sqrl/status`, `GET /auth/sqrl/refresh` and + `GET /auth/sqrl/sqrl.js` are served by the strategy itself (OmniAuth's `other_phase`), so + they never reach your controllers. - `GET /auth/sqrl/callback` builds the auth hash: `uid` is the identity key (base64url), `info` is empty by design, and `extra["sqrl"]` carries `suk`, `vuk`, `created`, `rekeyed_from`, `options`, `disabled`, `via` (`cps` or `poll`) and `user_ref`. @@ -23,4 +24,7 @@ end provider; `devise-sqrl` is the native alternative. Always pass `stores:` in production. The default in-memory stores are process-wide and -exist only so development works without configuration. +exist only so development works without configuration. The strategy takes the same +protocol and hardening options as the Rack middleware (`require_ip_match`, +`poll_requires_ip_match`, `allowed_hosts`, `host_cache_limit`, `before_issue`, +`before_handle`, `prune_every`, `insecure_http`); the gem README lists them. diff --git a/docs/integrations/rack-sinatra.md b/docs/integrations/rack-sinatra.md index 4ace725..aa505b2 100644 --- a/docs/integrations/rack-sinatra.md +++ b/docs/integrations/rack-sinatra.md @@ -1,6 +1,6 @@ -# Rack and Sinatra +# Rack, Sinatra and Roda -Gem: `sqrl-rack`. Examples: `examples/rack-app`, `examples/sinatra-app`. +Gem: `sqrl-rack`. Examples: `examples/rack-app`, `examples/sinatra-app`, `examples/roda-app`. ## Rack @@ -13,11 +13,16 @@ use SQRL::Rack::Middleware, after_login: "/" ``` -The middleware owns `POST /sqrl/cli`, `GET /sqrl/status`, `GET /sqrl/callback` and -`GET /sqrl/sqrl.js`. Every other request receives `env["sqrl.server"]`, a facade with -`login_url`, `login_block`, `script_tag`, `qr_svg`, `identity`, `authenticated?` and -`logout!`. Without `on_login`, the identity key is stored in the session under -`sqrl.identity` and `authenticated?` reads it back. +The middleware owns `POST /sqrl/cli`, `GET /sqrl/status`, `GET /sqrl/callback`, +`GET /sqrl/refresh` and `GET /sqrl/sqrl.js`. Every other request receives +`env["sqrl.server"]`, a facade with `login_url`, `login_block`, `script_tag`, `qr_svg`, +`refresh_url`, `identity`, `authenticated?` and `logout!`. Without `on_login`, the identity +key is stored in the session under `sqrl.identity` and `authenticated?` reads it back. + +Every `SQRL::Server::Config` option passes through (`ask`, `sin`, `require_ip_match`, +`allowed_hosts`, `before_issue`, `before_handle`, `prune_every`, …), plus the middleware's +own `poll_requires_ip_match` (default off), `host_cache_limit`, `failure_path` and +`insecure_http`. The gem README has the full tables. ## Sinatra @@ -34,8 +39,32 @@ end ``` Helpers: `sqrl_login_url`, `sqrl_qr_svg`, `sqrl_script_tag`, `sqrl_login_block`, -`sqrl_authenticated?`, `current_sqrl_identity`, `sqrl_logout!`. `enable :sessions` must -come before `register`. +`sqrl_authenticated?`, `current_sqrl_identity`, `sqrl_logout!` and `sqrl` (the facade). +Sessions must be enabled; `set :sqrl` may come before or after `register` because the +options are read on the first request. + +## Roda + +```ruby +require "roda/plugins/sqrl" + +class App < Roda + use Rack::Session::Cookie, secret: ENV.fetch("SESSION_SECRET"), same_site: :lax + plugin :sqrl, host: "example.com", stores: SQRL::Server::Memory.stores + + sqrl_on_login { |identity, env| env["rack.session"]["user"] = identity.idk_b64 } + + route do |r| + r.get("login") { sqrl_login_block } + r.root { sqrl_authenticated? ? "Hello #{current_sqrl_identity.idk_b64}" : r.redirect("/login") } + end +end +``` + +`plugin :sqrl` takes every middleware option and adds the same helpers as the Sinatra +extension. The session must come from a Rack session middleware added with `use` before the +plugin; Roda's own `sessions` plugin runs inside the routing tree, after the middleware, and +cannot be used for this. `roda` itself is not a dependency of `sqrl-rack`. ## Notes diff --git a/docs/integrations/rails.md b/docs/integrations/rails.md index aef48cb..29f9c1a 100644 --- a/docs/integrations/rails.md +++ b/docs/integrations/rails.md @@ -9,10 +9,16 @@ bin/rails generate sqrl:install bin/rails db:migrate ``` -The generator is idempotent and does five things: copies the migration for +The generator is idempotent and does six things: copies the migration for `sqrl_identities`, `sqrl_nuts` and `sqrl_pending_logins`; mounts the engine at `/sqrl`; -writes `config/initializers/sqrl.rb`; adds `has_many :sqrl_identities` to `User`; and -appends `<%= sqrl_login_block %>` to `app/views/sessions/new.html.erb` when it exists. +writes `config/initializers/sqrl.rb`; adds `has_many :sqrl_identities` to `User`; includes +the `sqrlonly`/`hardlock` password policies in the generated `SessionsController` and +`PasswordsController`; and appends `<%= sqrl_login_block %>` to +`app/views/sessions/new.html.erb` when it exists. + +The engine serves `POST /sqrl/cli`, `GET /sqrl/status`, `GET /sqrl/callback`, +`GET /sqrl/refresh`, `GET /sqrl/sqrl.js`, a stand-alone `GET /sqrl/login` page and +`GET /sqrl/identities` (list and unlink the signed-in user's identities). ## Rails 8 `Authentication` concern @@ -40,8 +46,24 @@ when those columns or writers exist. Replace it with `config.sqrl.create_user` w model needs more. `:link` attaches the new identity to `Current.user` (or `config.sqrl.current_user`); `:refuse` rejects it. +## Account policies + +`SQRL::Rails.sqrl_only?(user)` and `hard_locked?(user)` report what the user's SQRL client +asked for. `SQRL::Rails::PasswordPolicy::Sessions` refuses password login for `sqrlonly` +users and `PasswordPolicy::Passwords` refuses password reset for `hardlock` users; the +generator includes both in the Rails 8 generated controllers. + ## Operations -- `bin/rails sqrl:prune` deletes expired nuts and pending logins. -- Set `config.sqrl.host` in production. `config.sqrl.stores` defaults to ActiveRecord. +- `bin/rails sqrl:prune` deletes expired nuts and pending logins; `config.sqrl.prune_every` + does it opportunistically. +- Set `config.sqrl.host` in production (or `allowed_hosts` when it must be derived). + `config.sqrl.stores` is `:active_record` by default, or `:cache` for an + `ActiveSupport::Cache` store with atomic delete, or `:memory` for development. +- `config.sqrl.rate_limit = { to: 60, within: 1.minute }` throttles the SQRL routes per + client IP; `before_issue` / `before_handle` hooks may raise `SQRL::Server::RateLimited`. - The engine's `cli` action skips forgery protection; nothing else does. +- `insecure_http` (loopback-only plain HTTP) and `poll_requires_ip_match` (off by default) + behave as described in [docs/security.md](../security.md). + +The [gem README](../../gems/sqrl-rails/README.md) has the full option table. diff --git a/examples/devise-app/README.md b/examples/devise-app/README.md index 09b7c19..2696b68 100644 --- a/examples/devise-app/README.md +++ b/examples/devise-app/README.md @@ -28,13 +28,20 @@ the login), `SQRL_SIN=1` (send a secret-index challenge). Routes added by Devise for `:sqrl_authenticatable`: `GET /users/sqrl`, `POST /users/sqrl/cli` (protocol endpoint), `GET /users/sqrl/status`, -`GET /users/sqrl/callback`, `GET /users/sqrl/sqrl.js`, `GET /users/sqrl/identities` -(manage linked identities), `DELETE /users/sqrl/identities/:id`. +`GET /users/sqrl/callback`, `GET /users/sqrl/refresh`, `GET /users/sqrl/sqrl.js`, +`GET /users/sqrl/identities` (manage linked identities), `DELETE /users/sqrl/identities/:id`. Account policies: a user whose SQRL client asked for `sqrlonly` cannot log in with a password (Devise's password strategy is refused with "This account signs in with SQRL only."), and one who asked for `hardlock` cannot request or perform a password reset. +## Logging in with the browser extension + +Install the [SQRL Login extension](https://github.com/danielpclark/SQRL-extension) (Chrome +Web Store or Firefox Add-ons), create an identity, open the login page and click "Sign in +with SQRL". The extension needs either HTTPS (`SQRL_TLS_KEY`/`SQRL_TLS_CERT`; accept the +self-signed certificate in the browser once) or, on `localhost` only, `SQRL_INSECURE_HTTP=1`. + ## TLS, `sqrl://` and plain http SQRL login URLs are `sqrl://…` and always mean HTTPS, so a real SQRL client only works diff --git a/examples/omniauth-app/README.md b/examples/omniauth-app/README.md index 557593b..dcb2ed8 100644 --- a/examples/omniauth-app/README.md +++ b/examples/omniauth-app/README.md @@ -18,9 +18,17 @@ app renders the token from Rack::Protection (enabled by Sinatra's sessions) into form, so the default protection stays on. Rails applications get the same from the `omniauth-rails_csrf_protection` gem. -Environment: `SQRL_TLS_KEY`/`SQRL_TLS_CERT`, `SQRL_INSECURE_HTTP`, `SQRL_HOST` (public host placed in `sqrl://` URLs; defaults to the request -host), `SESSION_SECRET`, `SQRL_UNKNOWN_IDENTITY` (`create`, `link` or `refuse`), -`SQRL_IGNORE_IP`. Identities are kept in memory. +Environment: `SQRL_TLS_KEY`/`SQRL_TLS_CERT`, `SQRL_INSECURE_HTTP`, `SQRL_HOST` (public host +placed in `sqrl://` URLs; defaults to the request host), `SESSION_SECRET`, +`SQRL_UNKNOWN_IDENTITY` (`create`, `link` or `refuse`), `SQRL_IGNORE_IP`, `SQRL_ASK=1`, +`SQRL_SIN=1`. Identities are kept in memory. + +## Logging in with the browser extension + +Install the [SQRL Login extension](https://github.com/danielpclark/SQRL-extension) (Chrome +Web Store or Firefox Add-ons), create an identity, open the login page and click "Sign in +with SQRL". The extension needs either HTTPS (`SQRL_TLS_KEY`/`SQRL_TLS_CERT`; accept the +self-signed certificate in the browser once) or, on `localhost` only, `SQRL_INSECURE_HTTP=1`. ## TLS, `sqrl://` and plain http diff --git a/examples/rack-app/README.md b/examples/rack-app/README.md index 23ee0c8..16a922e 100644 --- a/examples/rack-app/README.md +++ b/examples/rack-app/README.md @@ -9,12 +9,22 @@ bin/dev # http://localhost:9292/ ``` Routes: `/` (home, shows login state), `/login` (QR, link and `sqrl.js`), `/protected` -(403 until logged in), `POST /logout`. On `localhost` over plain http the middleware +(403 until logged in), `POST /logout`. The middleware serves `/sqrl/cli`, `/sqrl/status`, +`/sqrl/callback`, `/sqrl/refresh` and `/sqrl/sqrl.js`. -Environment: `SQRL_TLS_KEY`/`SQRL_TLS_CERT`, `SQRL_INSECURE_HTTP`, `SQRL_HOST` (public host in `sqrl://` URLs), `SESSION_SECRET`, -`SQRL_UNKNOWN_IDENTITY` (`create`, `link` or `refuse`), `SQRL_IGNORE_IP` (set to disable -the IP match check, for proxies in development). Identities live in memory and vanish -when the process stops. +Environment: `SQRL_TLS_KEY`/`SQRL_TLS_CERT`, `SQRL_INSECURE_HTTP`, `SQRL_HOST` (public host +in `sqrl://` URLs), `SESSION_SECRET`, `SQRL_UNKNOWN_IDENTITY` (`create`, `link` or +`refuse`), `SQRL_IGNORE_IP` (set to disable the IP match check, for proxies in +development), `SQRL_ASK=1` (pose an Allow/Deny question; Deny refuses the login), +`SQRL_SIN=1` (send a secret-index challenge). Identities live in memory and vanish when +the process stops. + +## Logging in with the browser extension + +Install the [SQRL Login extension](https://github.com/danielpclark/SQRL-extension) (Chrome +Web Store or Firefox Add-ons), create an identity, open the login page and click "Sign in +with SQRL". The extension needs either HTTPS (`SQRL_TLS_KEY`/`SQRL_TLS_CERT`; accept the +self-signed certificate in the browser once) or, on `localhost` only, `SQRL_INSECURE_HTTP=1`. ## TLS, `sqrl://` and plain http diff --git a/examples/rails-auth-app/README.md b/examples/rails-auth-app/README.md index a873f1d..e66d053 100644 --- a/examples/rails-auth-app/README.md +++ b/examples/rails-auth-app/README.md @@ -22,14 +22,21 @@ Environment variables: `PORT`, `BIND`, `SQRL_TLS_KEY`/`SQRL_TLS_CERT`, `SQRL_INS the login), `SQRL_SIN=1` (send a secret-index challenge). Useful routes: `/sqrl/login` (stand-alone SQRL page), `POST /sqrl/cli` (protocol -endpoint), `/sqrl/status`, `/sqrl/callback`, `/sqrl/sqrl.js`, `/sqrl/identities` -(the signed-in user's SQRL identities, with an Unlink button). +endpoint), `/sqrl/status`, `/sqrl/callback`, `/sqrl/refresh`, `/sqrl/sqrl.js`, +`/sqrl/identities` (the signed-in user's SQRL identities, with an Unlink button). Account policies: the generator added `SQRL::Rails::PasswordPolicy::Sessions` to `SessionsController` and `::Passwords` to `PasswordsController`, so a user whose SQRL client asked for `sqrlonly` cannot log in with a password, and one who asked for `hardlock` cannot reset it. +## Logging in with the browser extension + +Install the [SQRL Login extension](https://github.com/danielpclark/SQRL-extension) (Chrome +Web Store or Firefox Add-ons), create an identity, open the login page and click "Sign in +with SQRL". The extension needs either HTTPS (`SQRL_TLS_KEY`/`SQRL_TLS_CERT`; accept the +self-signed certificate in the browser once) or, on `localhost` only, `SQRL_INSECURE_HTTP=1`. + ## TLS, `sqrl://` and plain http SQRL login URLs are `sqrl://…` and always mean HTTPS, so a real SQRL client only works diff --git a/examples/roda-app/README.md b/examples/roda-app/README.md index 253a8f7..91b33b6 100644 --- a/examples/roda-app/README.md +++ b/examples/roda-app/README.md @@ -12,13 +12,21 @@ Routes: `/` (home, shows the login state), `/login` (the SQRL login block), `/pr (403 until logged in), `POST /logout`. The SQRL endpoint, status poll, callback and script are served by the middleware under `/sqrl/`. -Environment: `SQRL_TLS_KEY`/`SQRL_TLS_CERT`, `SQRL_INSECURE_HTTP`, `SQRL_HOST` (public host for `sqrl://` URLs), `SQRL_ASK=1`, `SQRL_SIN=1`, +Environment: `SQRL_TLS_KEY`/`SQRL_TLS_CERT`, `SQRL_INSECURE_HTTP`, `SQRL_HOST` (public host +for `sqrl://` URLs), `SESSION_SECRET`, `SQRL_ASK=1`, `SQRL_SIN=1`, `SQRL_UNKNOWN_IDENTITY=create|link|refuse`, `SQRL_IGNORE_IP=1`. Roda's own `sessions` plugin is not used because the SQRL middleware runs before the routing tree; a Rack session middleware (`Rack::Session::Cookie` here) provides the session the middleware binds logins to. +## Logging in with the browser extension + +Install the [SQRL Login extension](https://github.com/danielpclark/SQRL-extension) (Chrome +Web Store or Firefox Add-ons), create an identity, open the login page and click "Sign in +with SQRL". The extension needs either HTTPS (`SQRL_TLS_KEY`/`SQRL_TLS_CERT`; accept the +self-signed certificate in the browser once) or, on `localhost` only, `SQRL_INSECURE_HTTP=1`. + ## TLS, `sqrl://` and plain http SQRL login URLs are `sqrl://…` and always mean HTTPS, so a real SQRL client only works diff --git a/examples/sinatra-app/README.md b/examples/sinatra-app/README.md index 0b18fe1..80a6614 100644 --- a/examples/sinatra-app/README.md +++ b/examples/sinatra-app/README.md @@ -9,7 +9,15 @@ bin/dev # http://localhost:9393/ Routes: `/`, `/login`, `/protected` (403 until logged in), `POST /logout`. The same environment variables as `examples/rack-app` apply (`SQRL_HOST`, `SESSION_SECRET`, -`SQRL_UNKNOWN_IDENTITY`, `SQRL_IGNORE_IP`). Identities are kept in memory. +`SQRL_UNKNOWN_IDENTITY`, `SQRL_IGNORE_IP`, `SQRL_ASK`, `SQRL_SIN`, +`SQRL_TLS_KEY`/`SQRL_TLS_CERT`, `SQRL_INSECURE_HTTP`). Identities are kept in memory. + +## Logging in with the browser extension + +Install the [SQRL Login extension](https://github.com/danielpclark/SQRL-extension) (Chrome +Web Store or Firefox Add-ons), create an identity, open the login page and click "Sign in +with SQRL". The extension needs either HTTPS (`SQRL_TLS_KEY`/`SQRL_TLS_CERT`; accept the +self-signed certificate in the browser once) or, on `localhost` only, `SQRL_INSECURE_HTTP=1`. ## TLS, `sqrl://` and plain http diff --git a/gems/devise-sqrl/README.md b/gems/devise-sqrl/README.md index 0932adb..b8b06df 100644 --- a/gems/devise-sqrl/README.md +++ b/gems/devise-sqrl/README.md @@ -40,6 +40,7 @@ end | `GET /users/sqrl/sqrl.js` | the browser-side script | | `GET /users/sqrl/refresh` | a fresh login URL for the page (JSON) | | `GET /users/sqrl/identities` | the signed-in user's identities, with Unlink | +| `DELETE /users/sqrl/identities/:id` | unlink one identity | ## How a login completes @@ -76,11 +77,12 @@ Protocol and storage settings live in `Rails.application.config.sqrl` (see ```ruby Devise.setup do |config| - config.sqrl_on_unknown_identity = :create # :create (default), :link or :refuse + config.sqrl_on_unknown_identity = :create # :create, :link or :refuse; nil (default) defers to config.sqrl (:create) config.sqrl_create_resource = ->(identity, klass) { klass.new(email: "...", password: SecureRandom.hex(32)) } config.sqrl_remember_me = false # treat SQRL logins as "remember me" config.sqrl_login_block = { link_text: "Sign in with SQRL" } config.sqrl_failure_path = nil # default: the scope's SQRL login page + config.sqrl_only_blocked_strategies = [:database_authenticatable] # refused for sqrlonly users end ``` @@ -145,11 +147,15 @@ under the Devise scope. The [sqrl-client](../sqrl-client) gem logs in without a browser: ```ruby -agent = SQRL::Client::Agent.new(identity: SQRL::Client::Identity.ephemeral) -result = agent.login("http://127.0.0.1:3000/users/sign_in") +transport = SQRL::Client::Transport.new(ca_file: "cert.pem") # the certificate you gave bin/dev via SQRL_TLS_CERT +agent = SQRL::Client::Agent.new(identity: SQRL::Client::Identity.ephemeral, transport: transport) +result = agent.login("https://127.0.0.1:3000/users/sign_in") result.authenticated? # => true; result.cookies carries the Devise session ``` +Against a server started with `SQRL_INSECURE_HTTP=1` (plain http on localhost), use +`Agent.new(identity:, insecure: true)` and an `http://` URL instead. + See [`examples/devise-app`](../../examples/devise-app) for a complete application; `bundle exec rake spec:devise-sqrl` runs this gem's specs against an in-gem dummy app. diff --git a/gems/omniauth-sqrl/README.md b/gems/omniauth-sqrl/README.md index 8f5637d..ebbe077 100644 --- a/gems/omniauth-sqrl/README.md +++ b/gems/omniauth-sqrl/README.md @@ -24,6 +24,7 @@ end | `POST /auth/sqrl/cli` | other phase | the SQRL client's protocol endpoint (`query`, `ident`, `disable`, `enable`, `remove`) | | `GET /auth/sqrl/status` | other phase | cookie-bound JSON poll used by `sqrl.js` for logins from another device | | `GET /auth/sqrl/sqrl.js` | other phase | the browser script | +| `GET /auth/sqrl/refresh` | other phase | a fresh login URL for the page when a nut expired (JSON) | | `GET /auth/sqrl/callback?t=TOKEN` | callback phase | Client Provided Session landing: the one-time token is claimed and the auth hash is built | | `GET /auth/sqrl/callback` | callback phase | completion from the poller (the browser's own pending login) | @@ -72,7 +73,11 @@ foreign, reused or expired token) or `sqrl_disabled`. | `title:` / `cancel_url:` | "Sign in with SQRL" / the origin | login page title and cancel link | | `info:` | `nil` | callable `(identity) -> Hash` to fill `info` | | `ip:` | `Rack::Request#ip` | callable resolving the client IP (trusted proxies) | -| `cli_path:` / `status_path:` / `script_path:` | under the provider prefix | endpoint paths | +| `cli_path:` / `status_path:` / `script_path:` / `refresh_path:` | under the provider prefix | endpoint paths | +| `allowed_hosts:` / `host_cache_limit:` | `nil` / 16 | accepted request hosts when `host:` is derived, and how many distinct ones are kept | +| `before_issue:` / `before_handle:` | `nil` | hooks that may raise `SQRL::Server::RateLimited` (answered with 429) | +| `prune_every:` | 1000 | opportunistic `prune!` every N requests (`nil` disables) | +| `logger:` | `nil` | logger for warnings and protocol traces | ## Devise diff --git a/gems/sqrl-rack/README.md b/gems/sqrl-rack/README.md index a753d12..6315890 100644 --- a/gems/sqrl-rack/README.md +++ b/gems/sqrl-rack/README.md @@ -1,6 +1,6 @@ # sqrl-rack -SQRL login for Rack applications and Sinatra: a middleware that mounts the SQRL endpoint, +SQRL login for Rack applications, Sinatra and Roda: a middleware that mounts the SQRL endpoint, the browser's status poll and the login callback; a Sinatra extension with view helpers; the browser-side `sqrl.js`; and QR code rendering. Built on [`sqrl-core`](../sqrl-core). @@ -32,9 +32,10 @@ run ->(env) { The middleware serves `POST /sqrl/cli` (the SQRL protocol endpoint), `GET /sqrl/status` (cookie-bound JSON poll), `GET /sqrl/callback` (login completion, with or without a CPS -token) and `GET /sqrl/sqrl.js`. Everything else gets `env["sqrl.server"]`, a -`SQRL::Rack::Facade` with `login_url`, `login_block`, `script_tag`, `qr_svg`, -`identity`, `authenticated?` and `logout!`. +token), `GET /sqrl/refresh` (a fresh login URL for the page) and `GET /sqrl/sqrl.js`. +Everything else gets `env["sqrl.server"]`, a `SQRL::Rack::Facade` with `login_url`, +`login_block`, `script_tag`, `qr_svg`, `refresh_url`, `identity`, `authenticated?` and +`logout!`. Every `SQRL::Server::Config` option is accepted (`on_unknown_identity`, `ask`, `sin`, `require_ip_match`, `nut_ttl`, `cps_token_ttl`, ...). Without `host:` the request host is @@ -179,8 +180,9 @@ element dispatches `sqrl:cps-detected`, `sqrl:authenticated` (`detail.next`), 5. The middleware stores the identity in the session, runs `on_login`, and redirects to the pending login's `return_to` or `after_login`. -See [`examples/rack-app`](../../examples/rack-app) and -[`examples/sinatra-app`](../../examples/sinatra-app). and [`examples/roda-app`](../../examples/roda-app). +See [`examples/rack-app`](../../examples/rack-app), +[`examples/sinatra-app`](../../examples/sinatra-app) and +[`examples/roda-app`](../../examples/roda-app). ## Testing diff --git a/gems/sqrl-rails/README.md b/gems/sqrl-rails/README.md index 4c06a1a..9a54ad2 100644 --- a/gems/sqrl-rails/README.md +++ b/gems/sqrl-rails/README.md @@ -27,6 +27,8 @@ The generator: - mounts the engine: `mount SQRL::Rails::Engine, at: "/sqrl", as: :sqrl`; - writes `config/initializers/sqrl.rb` (every option documented inline); - adds `has_many :sqrl_identities` to `app/models/user.rb`; +- includes `SQRL::Rails::PasswordPolicy::Sessions` / `::Passwords` in the generated + `SessionsController` and `PasswordsController` when they exist (see "Account policies"); - appends `<%= sqrl_login_block %>` to `app/views/sessions/new.html.erb` when that view exists (the Rails 8 generated login form). @@ -92,7 +94,8 @@ is an `SQRL::Server::Identity` (`idk_b64`, `user_ref`, `disabled?`, …). ## Helpers In views: `sqrl_login_block(return_to:, cancel_url:, link_user:, script:, **login_block_options)`, -`sqrl_login_url`, `sqrl_qr_svg`, `sqrl_script_tag`, `sqrl_status_path`, `sqrl_script_path`. +`sqrl_login_url`, `sqrl_qr_svg`, `sqrl_script_tag`, `sqrl_status_path`, `sqrl_script_path`, +`sqrl_refresh_path`, `sqrl_identities_path`. In controllers: `current_sqrl_identity`, `sqrl_authenticated?`, `sqrl_logout!` (call it from your sign-out action), `sqrl_endpoint`.