mirror of
https://github.com/penpot/penpot.git
synced 2026-11-16 15:11:17 +00:00
🐛 Allow OIDC registration with password login disabled (#12974)
* 🐛 Allow OIDC registration with password login disabled The register-profile command rejected every registration without the login-with-password flag, including SSO ones, while the OIDC callback already allowed :oidc-registration as an alternative, so new OIDC users were stuck at the register screen with a 400 registration-disabled error. The gate now branches on the verified token backend: password tokens keep the previous checks, SSO tokens only require :registration or :oidc-registration through a predicate shared with the callback, so the two gates cannot drift apart again. Flags and invitation checks are split into single-responsibility helpers, and tokens without a backend claim are rejected loudly by schema instead of defaulting silently. Covered by regression tests for the SSO matrix, canceled invitations, the missing-backend case and the no-password-fallback, plus a configuration doc note. Closes #12964 AI-assisted-by: Muse Spark 1.3 Contributor * 🐛 Gate SSO registration by provider type, accept invitations Follow up the review on #12974. The SSO registration gate now treats a team invitation token as a substitute for :registration / :oidc-registration, in both the OIDC callback and register-profile, mirroring the password flow: the callback redirects to the register screen when an invitation is present, and register-profile revalidates the invitation row under a row lock before creating the profile when no SSO flag is set, raising :invalid-token instead of creating an account that cannot join a team. The SSO branch is restricted to OIDC-typed backends (oidc-provider-types); a prepared-register token carrying any other backend is rejected with :invalid-token instead of silently taking the SSO rules. The flags and invitation checks are shared by one check-registration helper in register-profile; the prepare command runs flags, then the email-mismatch restriction, then the invitation row lookup, so the password login flag fails closed first. The schema defs are private, the create-profile default uses penpot-backend, the OIDC callback test decodes the redirect token to assert the :prepared-register claims, and the docs and the auth memory state the invitation path for SSO registration. Regression tests cover invitation-only registration, canceled invitations with and without SSO flags, unknown backends, and the double-fault precedence in prepare-register. AI-assisted-by: inkling-2-small-free * 🐛 Require invitation email match for SSO registration Close the hole left by treating any invitation token as a substitute for the SSO registration flags. register-profile now requires the invitation member-email to match the prepared-register email, raising :email-does-not-match-invitation otherwise, mirroring the password flow. The OIDC callback verifies the team-invitation JWT and the email before redirecting to register instead of trusting raw presence. Covered by the requested mismatch regression test plus callback tests for mismatch and garbage tokens. AI-assisted-by: Muse Spark 1.3 Contributor * ♻️ Share registration gate between prepare and register-profile After the email-match fix, check-registration runs flags, email and invitation row in the same order as validate-register-attempt!. The prepare command now calls the shared helper instead of inlining the trio, and the stale docstring rationale is gone, so future invitation rule changes land in one place. AI-assisted-by: Muse Spark 1.3 Contributor
This commit is contained in:
parent
0e4be21320
commit
f3c1230b79
@ -12,7 +12,7 @@
|
||||
- Lockout and RPC rate limits share the `app.http.errors/handle-error :rate-limit` HTTP path: status 429, body `{:type :rate-limit :code ... :hint ... :ttl ...}`, and any supplied `::http/headers` preserved. Account lockout raises `:code :account-locked` and, when it carries a non-nil `:ttl` (seconds), the handler adds `retry-after`. The RPC limiter (`app.rpc.rlimit`) raises `:code :request-blocked` and sets `retry-after` itself in `::http/headers` (seconds until the longest rejecting limit resets), alongside `x-rate-limit-remaining`/`x-rate-limit-reset`. CORS (`app.http.middleware/with-cors-headers`) exposes `content-type`, `retry-after`, and both `x-rate-limit-*` headers. External flags: `enable-account-lockout`, `enable-rpc-rlimit`.
|
||||
- Logout may return an OIDC provider redirect URI when the session claims include provider/session data and the provider has a logout URI.
|
||||
- Invitation tokens are verified through token issuers and only accepted when the token member id/email matches the authenticated profile; otherwise login proceeds without consuming the invitation.
|
||||
- When public registration is disabled, invitation-based password registration also requires a matching, non-expired `team_invitation` row; registration revalidates it under a row lock before creating the profile.
|
||||
- When public registration is disabled, invitation-based password registration also requires a matching, non-expired `team_invitation` row; registration revalidates it under a row lock before creating the profile. SSO registration (OIDC and compatible providers) follows the OIDC callback gate: it requires `:registration` or `:oidc-registration`, or a team invitation token issued for the registering email (an invitation substitutes the flags only when `member-email` matches the OIDC/`prepared-register` email via `clean-email`, as in the password flow, which raises `:email-does-not-match-invitation` otherwise). The OIDC callback verifies the invitation JWT and the email before redirecting to register, and `register-profile` revalidates the invitation under a row lock when no SSO flag is set; it never requires password login. Only OIDC-typed backends (`oidc-provider-types` in `app.auth.oidc`) take the SSO registration gate; any other `:backend` in a prepared-register token is rejected as `:invalid-token`.
|
||||
- HTTP/session parsing details such as cookie/header precedence, JWT session token versions, and SameSite behavior are in `mem:backend/subtleties`.
|
||||
|
||||
## Permission model
|
||||
|
||||
@ -1062,6 +1062,32 @@
|
||||
:organization-id organization-id
|
||||
:organization-name organization-name}))))))
|
||||
|
||||
(def oidc-provider-types
|
||||
"Backends authenticating through an OIDC-compatible provider.
|
||||
Only these backends take the SSO registration gate."
|
||||
#{"oidc" "google" "github" "gitlab"})
|
||||
|
||||
(defn sso-registration-allowed?
|
||||
"SSO registration is allowed when public registration or explicit
|
||||
OIDC registration is enabled. Shared by the callback gate and the
|
||||
`register-profile` token gate — keep one definition."
|
||||
[]
|
||||
(or (contains? cf/flags :registration)
|
||||
(contains? cf/flags :oidc-registration)))
|
||||
|
||||
(defn- valid-invitation-for?
|
||||
"Returns true when `invitation-token` is a verifiable
|
||||
`:team-invitation` JWT issued for `email`. Never throws: a garbage
|
||||
token means there is no valid invitation."
|
||||
[cfg invitation-token email]
|
||||
(try
|
||||
(boolean
|
||||
(when (and (some? invitation-token) (some? email))
|
||||
(let [invitation (tokens/verify cfg {:token invitation-token :iss :team-invitation})]
|
||||
(= (profile/clean-email (:member-email invitation))
|
||||
(profile/clean-email email)))))
|
||||
(catch Throwable _ false)))
|
||||
|
||||
(defn- callback-handler
|
||||
[cfg {:keys [params] :as request}]
|
||||
(if-let [error (get params :error)]
|
||||
@ -1094,8 +1120,8 @@
|
||||
(redirect-with-error "email-domain-not-allowed")
|
||||
|
||||
:else
|
||||
(if (or (contains? cf/flags :registration)
|
||||
(contains? cf/flags :oidc-registration))
|
||||
(if (or (sso-registration-allowed?)
|
||||
(valid-invitation-for? cfg (:invitation-token info) (:email info)))
|
||||
(redirect-to-register cfg info provider)
|
||||
(redirect-with-error "registration-disabled")))
|
||||
|
||||
|
||||
@ -46,6 +46,10 @@
|
||||
(def schema:token
|
||||
[::sm/word-string {:max 6000}])
|
||||
|
||||
(def ^:private penpot-backend
|
||||
"Auth backend identifier for the password flow."
|
||||
"penpot")
|
||||
|
||||
(defn- elapsed-verify-threshold?
|
||||
[profile]
|
||||
(let [elapsed (ct/diff (:modified-at profile) (ct/now))
|
||||
@ -226,25 +230,72 @@
|
||||
|
||||
;; ---- COMMAND: Prepare Register
|
||||
|
||||
(defn- validate-registration-flags!
|
||||
([cfg invitation]
|
||||
(validate-registration-flags! cfg invitation false))
|
||||
([cfg invitation lock-invitation?]
|
||||
(when-not (contains? cf/flags :login-with-password)
|
||||
(ex/raise :type :restriction
|
||||
:code :registration-disabled
|
||||
:hint "registration disabled"))
|
||||
(defn- check-registration-flags
|
||||
"The `:backend` is the one embedded in the verified
|
||||
`:prepared-register` token: the password flow backend, one of the
|
||||
`oidc/oidc-provider-types` backends for SSO flows, or any other
|
||||
value, which is rejected loudly."
|
||||
[backend invitation]
|
||||
(cond
|
||||
(= backend penpot-backend)
|
||||
(do
|
||||
(when-not (contains? cf/flags :login-with-password)
|
||||
(ex/raise :type :restriction
|
||||
:code :registration-disabled
|
||||
:hint "registration disabled"))
|
||||
|
||||
(when-not (contains? cf/flags :registration)
|
||||
(if (nil? invitation)
|
||||
(ex/raise :type :restriction
|
||||
:code :registration-disabled
|
||||
:hint "registration disabled")
|
||||
(let [opts (when lock-invitation? {::db/for-update true})]
|
||||
(when (nil? (teams-invitations/active-invitation cfg invitation opts))
|
||||
(ex/raise :type :validation
|
||||
:code :invalid-token
|
||||
:hint "no active invitation associated with the token")))))))
|
||||
(when-not (or (contains? cf/flags :registration)
|
||||
(some? invitation))
|
||||
(ex/raise :type :restriction
|
||||
:code :registration-disabled
|
||||
:hint "registration disabled")))
|
||||
|
||||
(contains? oidc/oidc-provider-types backend)
|
||||
;; SSO backends share the OIDC callback gate
|
||||
;; (`oidc/sso-registration-allowed?`): registration is allowed with
|
||||
;; `:registration` or `:oidc-registration`, without requiring
|
||||
;; password login. An invitation token is a substitute for the
|
||||
;; flags, as in the password flow.
|
||||
(when-not (or (oidc/sso-registration-allowed?)
|
||||
(some? invitation))
|
||||
(ex/raise :type :restriction
|
||||
:code :registration-disabled
|
||||
:hint "registration disabled"))
|
||||
|
||||
:else
|
||||
(ex/raise :type :validation
|
||||
:code :invalid-token
|
||||
:hint "unsupported registration backend")))
|
||||
|
||||
(defn- check-registration-invitation
|
||||
"Verifies that the invitation is still active. No-op unless a live
|
||||
invitation is required: a backend whose registration flags do not
|
||||
allow public registration, with an invitation at hand."
|
||||
[cfg backend invitation lock-invitation?]
|
||||
(let [flag-allows? (if (= backend penpot-backend)
|
||||
(contains? cf/flags :registration)
|
||||
(oidc/sso-registration-allowed?))]
|
||||
(when (and (some? invitation)
|
||||
(not flag-allows?))
|
||||
(let [opts (when lock-invitation? {::db/for-update true})]
|
||||
(when (nil? (teams-invitations/active-invitation cfg invitation opts))
|
||||
(ex/raise :type :validation
|
||||
:code :invalid-token
|
||||
:hint "no active invitation associated with the token"))))))
|
||||
|
||||
(defn- check-registration
|
||||
"Shared registration gate (register-profile and prepare-register):
|
||||
validates the flags, the invitation email and the team invitation
|
||||
row in order."
|
||||
[cfg backend invitation email lock-invitation?]
|
||||
(check-registration-flags backend invitation)
|
||||
(when (and (some? invitation)
|
||||
(not= (profile/clean-email (:member-email invitation))
|
||||
(profile/clean-email email)))
|
||||
(ex/raise :type :restriction
|
||||
:code :email-does-not-match-invitation
|
||||
:hint "email should match the invitation"))
|
||||
(check-registration-invitation cfg backend invitation lock-invitation?))
|
||||
|
||||
(defn- validate-register-attempt!
|
||||
[cfg params]
|
||||
@ -254,23 +305,7 @@
|
||||
{:token (:invitation-token params)
|
||||
:iss :team-invitation}))]
|
||||
|
||||
(when (or (not (contains? cf/flags :login-with-password))
|
||||
(and (not (contains? cf/flags :registration))
|
||||
(not invitation?)))
|
||||
(ex/raise :type :restriction
|
||||
:code :registration-disabled
|
||||
:hint "registration disabled"))
|
||||
|
||||
(when (and invitation?
|
||||
(not= (profile/clean-email (:email params))
|
||||
(profile/clean-email (:member-email invitation))))
|
||||
(ex/raise :type :restriction
|
||||
:code :email-does-not-match-invitation
|
||||
:hint "email should match the invitation"))
|
||||
|
||||
(when (and invitation?
|
||||
(not (contains? cf/flags :registration)))
|
||||
(validate-registration-flags! cfg invitation)))
|
||||
(check-registration cfg penpot-backend invitation (:email params) false))
|
||||
|
||||
(when (and (email.blacklist/enabled? cfg)
|
||||
(email.blacklist/contains? cfg (:email params)))
|
||||
@ -342,7 +377,7 @@
|
||||
:fullname fullname
|
||||
:password (:password params)
|
||||
:invitation-token (:invitation-token params)
|
||||
:backend "penpot"
|
||||
:backend penpot-backend
|
||||
:iss :prepared-register
|
||||
:exp (ct/in-future {:days 7})
|
||||
:props props}
|
||||
@ -414,7 +449,7 @@
|
||||
locale (when (and (string? locale) (not (str/blank? locale)))
|
||||
locale)
|
||||
|
||||
backend (:backend params "penpot")
|
||||
backend (:backend params penpot-backend)
|
||||
is-demo (:is-demo params false)
|
||||
is-muted (:is-muted params false)
|
||||
is-active (:is-active params false)
|
||||
@ -500,12 +535,25 @@
|
||||
:token vtoken
|
||||
:extra-data ptoken}))))
|
||||
|
||||
(def ^:private schema:prepared-register-claims
|
||||
[:map {:title "PreparedRegisterClaims"}
|
||||
[:backend ::sm/text]
|
||||
[:email ::sm/email]])
|
||||
|
||||
(def ^:private valid-prepared-register-claims?
|
||||
(sm/lazy-validator schema:prepared-register-claims))
|
||||
|
||||
(defn register-profile
|
||||
[{:keys [::db/conn] :as cfg} {:keys [token] :as params}]
|
||||
(let [claims (tokens/verify cfg {:token token :iss :prepared-register})
|
||||
_ (when-not (valid-prepared-register-claims? claims)
|
||||
(ex/raise :type :validation
|
||||
:code :invalid-token
|
||||
:hint "prepared-register token contains unexpected data"))
|
||||
backend (:backend claims)
|
||||
invitation (when-let [token (:invitation-token claims)]
|
||||
(tokens/verify cfg {:token token :iss :team-invitation}))
|
||||
_ (validate-registration-flags! cfg invitation true)
|
||||
_ (check-registration cfg backend invitation (:email claims) true)
|
||||
params (cond-> claims
|
||||
(:accept-newsletter-updates params)
|
||||
(update :props assoc :newsletter-updates true))
|
||||
|
||||
@ -447,6 +447,76 @@
|
||||
loc (redirect-location result)]
|
||||
(t/is (.contains loc "error=registration-disabled")))))))
|
||||
|
||||
(t/deftest callback-with-invitation-and-no-flags-redirects-to-register
|
||||
;; Review of #12974: a verifiable invitation issued for the OIDC
|
||||
;; email acts as a substitute for the SSO registration flags, so the
|
||||
;; user reaches the register screen instead of the
|
||||
;; registration-disabled error. The JWT is verified and the email is
|
||||
;; compared here; the invitation row is revalidated under a row lock
|
||||
;; in `register-profile`.
|
||||
(let [cfg (dissoc base-cfg :app.email/blacklist :app.email/whitelist)
|
||||
invitation (tokens/generate cfg {:iss :team-invitation
|
||||
:exp (ct/in-future {:hours 1})
|
||||
:member-email "u@e.com"})
|
||||
state (make-state-token cfg {:invitation-token invitation})
|
||||
request (default-request cfg :state state)]
|
||||
(binding [cf/config {:public-uri "http://localhost:3449"}
|
||||
cf/flags #{}]
|
||||
(with-redefs [app.auth.oidc/resolve-provider (constantly {:type "oidc" :id "oidc"})
|
||||
app.auth.oidc/get-info (constantly {:email "u@e.com" :fullname "U"
|
||||
:backend "oidc" :email-verified false
|
||||
:invitation-token invitation
|
||||
:props {}})
|
||||
app.auth.oidc/get-profile (constantly nil)]
|
||||
(let [result (#'oidc/callback-handler cfg request)
|
||||
loc (redirect-location result)
|
||||
claims (tokens/decode cfg (location-token loc))]
|
||||
(t/is (.contains loc "screen=auth-register-validate"))
|
||||
(t/is (.contains loc "token="))
|
||||
(t/is (= :prepared-register (:iss claims))
|
||||
"the redirect token must be a :prepared-register token")
|
||||
(t/is (= invitation (:invitation-token claims))
|
||||
"the invitation token must travel inside the prepared-register claims"))))))
|
||||
|
||||
(t/deftest callback-with-invitation-email-mismatch-redirects-to-registration-disabled
|
||||
;; Review of #12974: an invitation issued for another email must not
|
||||
;; unlock registration with closed registration.
|
||||
(let [cfg (dissoc base-cfg :app.email/blacklist :app.email/whitelist)
|
||||
invitation (tokens/generate cfg {:iss :team-invitation
|
||||
:exp (ct/in-future {:hours 1})
|
||||
:member-email "alice@example.com"})
|
||||
state (make-state-token cfg {:invitation-token invitation})
|
||||
request (default-request cfg :state state)]
|
||||
(binding [cf/config {:public-uri "http://localhost:3449"}
|
||||
cf/flags #{}]
|
||||
(with-redefs [app.auth.oidc/resolve-provider (constantly {:type "oidc" :id "oidc"})
|
||||
app.auth.oidc/get-info (constantly {:email "attacker@example.com" :fullname "A"
|
||||
:backend "oidc" :email-verified false
|
||||
:invitation-token invitation
|
||||
:props {}})
|
||||
app.auth.oidc/get-profile (constantly nil)]
|
||||
(let [result (#'oidc/callback-handler cfg request)
|
||||
loc (redirect-location result)]
|
||||
(t/is (.contains loc "error=registration-disabled")))))))
|
||||
|
||||
(t/deftest callback-with-garbage-invitation-redirects-to-registration-disabled
|
||||
;; Review of #12974: raw presence is not enough — an unverifiable
|
||||
;; invitation string must not reach the register screen.
|
||||
(let [cfg (dissoc base-cfg :app.email/blacklist :app.email/whitelist)
|
||||
state (make-state-token cfg {:invitation-token "inv-123"})
|
||||
request (default-request cfg :state state)]
|
||||
(binding [cf/config {:public-uri "http://localhost:3449"}
|
||||
cf/flags #{}]
|
||||
(with-redefs [app.auth.oidc/resolve-provider (constantly {:type "oidc" :id "oidc"})
|
||||
app.auth.oidc/get-info (constantly {:email "u@e.com" :fullname "U"
|
||||
:backend "oidc" :email-verified false
|
||||
:invitation-token "inv-123"
|
||||
:props {}})
|
||||
app.auth.oidc/get-profile (constantly nil)]
|
||||
(let [result (#'oidc/callback-handler cfg request)
|
||||
loc (redirect-location result)]
|
||||
(t/is (.contains loc "error=registration-disabled")))))))
|
||||
|
||||
(t/deftest callback-profile-blocked
|
||||
(let [cfg (dissoc base-cfg :app.email/blacklist :app.email/whitelist)
|
||||
state (make-state-token cfg {})
|
||||
|
||||
@ -954,6 +954,10 @@
|
||||
(t/is (= :email-does-not-match-invitation (:code edata))))))
|
||||
|
||||
(t/deftest prepare-register-with-invitation-and-disabled-registration-and-wrong-email
|
||||
;; The email check runs before the invitation row lookup, so a
|
||||
;; mismatched email is reported even when the invitation row is gone.
|
||||
;; Flags stay `#{:login-with-password}`: password registration is
|
||||
;; allowed only via invitation.
|
||||
(with-redefs [app.config/flags #{:login-with-password}]
|
||||
(let [itoken (tokens/generate th/*system*
|
||||
{:iss :team-invitation
|
||||
@ -961,7 +965,6 @@
|
||||
:role :editor
|
||||
:team-id uuid/zero
|
||||
:member-email "user2@example.com"})
|
||||
|
||||
data {::th/type :prepare-register-profile
|
||||
:invitation-token itoken
|
||||
:email "user@example.com"
|
||||
@ -1013,6 +1016,216 @@
|
||||
(t/is (= :registration-disabled (-> out :error ex-data :code)))
|
||||
(t/is (nil? (th/db-get :profile {:email email})))))))))
|
||||
|
||||
(defn- create-oidc-register-token
|
||||
"Mint a `:prepared-register` token shaped like the ones the OIDC
|
||||
callback produces in `redirect-to-register` (no real provider needed)."
|
||||
[email extra]
|
||||
(tokens/generate th/*system*
|
||||
(merge {:iss :prepared-register
|
||||
:exp (ct/in-future "48h")
|
||||
:backend "oidc"
|
||||
:email email
|
||||
:fullname "OIDC User"
|
||||
:email-verified true
|
||||
:props {}}
|
||||
extra)))
|
||||
|
||||
(t/deftest register-profile-allows-oidc-registration-with-password-login-disabled
|
||||
;; Issue #12964: with password login and public registration disabled,
|
||||
;; a new user arriving from OIDC must still be able to register when
|
||||
;; `oidc-registration` is enabled.
|
||||
(with-redefs [app.config/flags #{:login-with-oidc :oidc-registration}]
|
||||
(let [email "oidc-user@example.com"
|
||||
token (create-oidc-register-token email nil)
|
||||
out (th/command! {::th/type :register-profile
|
||||
:token token})
|
||||
result (:result out)
|
||||
mdata (meta result)]
|
||||
(t/is (th/success? out))
|
||||
;; A session is minted: the user lands on the dashboard.
|
||||
(t/is (seq (:app.rpc/response-transform-fns mdata)))
|
||||
(let [profile (th/db-get :profile {:email email})]
|
||||
(t/is (some? profile))
|
||||
(t/is (= "oidc" (:auth-backend profile)))
|
||||
(t/is (true? (:is-active profile))))
|
||||
;; No password fallback while password login is disabled.
|
||||
(let [login-out (th/command! {::th/type :login-with-password
|
||||
:email email
|
||||
:password "Whatever1!"})]
|
||||
(t/is (not (th/success? login-out)))
|
||||
(t/is (= :restriction (-> login-out :error ex-data :type)))
|
||||
(t/is (= :login-disabled (-> login-out :error ex-data :code)))))))
|
||||
|
||||
(t/deftest register-profile-rejects-oidc-without-registration-flags
|
||||
(with-redefs [app.config/flags #{:login-with-oidc}]
|
||||
(let [email "oidc-rejected@example.com"
|
||||
token (create-oidc-register-token email nil)
|
||||
out (th/command! {::th/type :register-profile
|
||||
:token token})]
|
||||
(t/is (not (th/success? out)))
|
||||
(t/is (= :registration-disabled (-> out :error ex-data :code)))
|
||||
(t/is (nil? (th/db-get :profile {:email email}))))))
|
||||
|
||||
(t/deftest register-profile-allows-oidc-with-public-registration-and-password-login-disabled
|
||||
(with-redefs [app.config/flags #{:login-with-oidc :registration}]
|
||||
(let [email "oidc-public@example.com"
|
||||
token (create-oidc-register-token email nil)
|
||||
out (th/command! {::th/type :register-profile
|
||||
:token token})]
|
||||
(t/is (th/success? out))
|
||||
(let [profile (th/db-get :profile {:email email})]
|
||||
(t/is (some? profile))
|
||||
(t/is (= "oidc" (:auth-backend profile)))))))
|
||||
|
||||
(t/deftest register-profile-allows-oidc-with-invitation-and-registration-disabled
|
||||
(let [email "oidc-invited@example.com"
|
||||
fixture (create-invitation-fixture email (ct/in-future "48h"))]
|
||||
(with-redefs [app.config/flags #{:login-with-oidc :oidc-registration}]
|
||||
(let [itoken (create-test-invitation-token fixture email)
|
||||
token (create-oidc-register-token email {:invitation-token itoken})
|
||||
out (th/command! {::th/type :register-profile
|
||||
:token token})
|
||||
result (:result out)
|
||||
mdata (meta result)]
|
||||
(t/is (th/success? out))
|
||||
;; Invitation branch: the token is echoed back and a session is
|
||||
;; minted so the frontend can complete the team-invitation flow.
|
||||
(t/is (string? (:invitation-token result)))
|
||||
(t/is (seq (:app.rpc/response-transform-fns mdata)))
|
||||
(let [profile (th/db-get :profile {:email email})]
|
||||
(t/is (some? profile))
|
||||
(t/is (= "oidc" (:auth-backend profile))))))))
|
||||
|
||||
(t/deftest register-profile-allows-oidc-with-canceled-invitation
|
||||
;; The invitation row is only consulted when no SSO registration
|
||||
;; flag is set: with `:oidc-registration` (as here), registration
|
||||
;; succeeds even when the invitation was canceled, and team
|
||||
;; membership fails later at `verify-token`.
|
||||
(let [email "oidc-canceled@example.com"
|
||||
fixture (create-invitation-fixture email (ct/in-future "48h"))]
|
||||
(with-redefs [app.config/flags #{:login-with-oidc :oidc-registration}]
|
||||
(let [itoken (create-test-invitation-token fixture email)
|
||||
token (create-oidc-register-token email {:invitation-token itoken})]
|
||||
(th/db-delete! :team-invitation
|
||||
{:team-id (:id (:team fixture))
|
||||
:email-to email})
|
||||
(let [out (th/command! {::th/type :register-profile
|
||||
:token token})
|
||||
result (:result out)
|
||||
mdata (meta result)]
|
||||
(t/is (th/success? out))
|
||||
(t/is (string? (:invitation-token result)))
|
||||
(t/is (seq (:app.rpc/response-transform-fns mdata)))
|
||||
(let [profile (th/db-get :profile {:email email})]
|
||||
(t/is (some? profile))
|
||||
(t/is (= "oidc" (:auth-backend profile))))
|
||||
;; The team is not joined: with the invitation row gone,
|
||||
;; accepting it fails.
|
||||
(let [vout (th/command! {::th/type :verify-token
|
||||
:token (:invitation-token result)})]
|
||||
(t/is (not (th/success? vout)))
|
||||
(t/is (= :validation (-> vout :error ex-data :type)))
|
||||
(t/is (= :invalid-token (-> vout :error ex-data :code)))))))))
|
||||
|
||||
(t/deftest register-profile-rejects-prepared-token-without-backend
|
||||
;; The `:backend` claim is mandatory: a prepared-register token
|
||||
;; without it is rejected loudly instead of falling into any
|
||||
;; registration branch.
|
||||
(with-redefs [app.config/flags #{:login-with-oidc :oidc-registration}]
|
||||
(let [token (tokens/generate th/*system*
|
||||
{:iss :prepared-register
|
||||
:exp (ct/in-future "48h")
|
||||
:email "no-backend@example.com"
|
||||
:fullname "No Backend"
|
||||
:email-verified true
|
||||
:props {}})
|
||||
out (th/command! {::th/type :register-profile
|
||||
:token token})]
|
||||
(t/is (not (th/success? out)))
|
||||
(t/is (= :validation (-> out :error ex-data :type)))
|
||||
(t/is (= :invalid-token (-> out :error ex-data :code)))
|
||||
(t/is (nil? (th/db-get :profile {:email "no-backend@example.com"}))))))
|
||||
|
||||
(t/deftest register-profile-rejects-non-oidc-backend-token
|
||||
;; The SSO registration gate only applies to backends of OIDC type;
|
||||
;; a token carrying any other backend is rejected loudly instead of
|
||||
;; silently taking the SSO branch.
|
||||
(with-redefs [app.config/flags #{:login-with-oidc :oidc-registration}]
|
||||
(let [token (tokens/generate th/*system*
|
||||
{:iss :prepared-register
|
||||
:exp (ct/in-future "48h")
|
||||
:backend "ldap"
|
||||
:email "unknown-backend@example.com"
|
||||
:fullname "Unknown Backend"
|
||||
:email-verified true
|
||||
:props {}})
|
||||
out (th/command! {::th/type :register-profile
|
||||
:token token})]
|
||||
(t/is (not (th/success? out)))
|
||||
(t/is (= :validation (-> out :error ex-data :type)))
|
||||
(t/is (= :invalid-token (-> out :error ex-data :code)))
|
||||
(t/is (nil? (th/db-get :profile {:email "unknown-backend@example.com"}))))))
|
||||
|
||||
(t/deftest register-profile-allows-oidc-with-invitation-and-no-registration-flags
|
||||
;; Review of #12974: an invitation token is a substitute for the
|
||||
;; SSO registration flags, as it is for the password flow. With no
|
||||
;; `:registration` nor `:oidc-registration` flag, a user arriving
|
||||
;; through a team invitation can still register via OIDC.
|
||||
(let [email "oidc-invited-noflags@example.com"
|
||||
fixture (create-invitation-fixture email (ct/in-future "48h"))]
|
||||
(with-redefs [app.config/flags #{:login-with-oidc}]
|
||||
(let [itoken (create-test-invitation-token fixture email)
|
||||
token (create-oidc-register-token email {:invitation-token itoken})
|
||||
out (th/command! {::th/type :register-profile
|
||||
:token token})
|
||||
result (:result out)
|
||||
mdata (meta result)]
|
||||
(t/is (th/success? out))
|
||||
;; Invitation branch: the token is echoed back and a session is
|
||||
;; minted so the frontend can complete the team-invitation flow.
|
||||
(t/is (string? (:invitation-token result)))
|
||||
(t/is (seq (:app.rpc/response-transform-fns mdata)))
|
||||
(let [profile (th/db-get :profile {:email email})]
|
||||
(t/is (some? profile))
|
||||
(t/is (= "oidc" (:auth-backend profile))))))))
|
||||
|
||||
(t/deftest register-profile-rejects-oidc-invitation-email-mismatch-with-no-registration-flags
|
||||
;; Review of #12974: the invitation is a substitute for the SSO
|
||||
;; registration flags only when it was issued for the registering
|
||||
;; email. A forwarded invitation for another email must not unlock
|
||||
;; registration with closed registration.
|
||||
(let [invited-email "oidc-invited-other@example.com"
|
||||
attacker-mail "oidc-attacker-noflags@example.com"
|
||||
fixture (create-invitation-fixture invited-email (ct/in-future "48h"))]
|
||||
(with-redefs [app.config/flags #{:login-with-oidc}]
|
||||
(let [itoken (create-test-invitation-token fixture invited-email)
|
||||
token (create-oidc-register-token attacker-mail {:invitation-token itoken})
|
||||
out (th/command! {::th/type :register-profile
|
||||
:token token})]
|
||||
(t/is (not (th/success? out)))
|
||||
(t/is (= :restriction (-> out :error ex-data :type)))
|
||||
(t/is (= :email-does-not-match-invitation (-> out :error ex-data :code)))
|
||||
(t/is (nil? (th/db-get :profile {:email attacker-mail})))))))
|
||||
|
||||
(t/deftest register-profile-rejects-oidc-with-canceled-invitation-and-no-registration-flags
|
||||
;; Review of #12974: with no registration flag set, the invitation
|
||||
;; row is revalidated under a row lock before creating the profile.
|
||||
;; A canceled invitation stops signup and no account is created.
|
||||
(let [email "oidc-canceled-noflags@example.com"
|
||||
fixture (create-invitation-fixture email (ct/in-future "48h"))]
|
||||
(with-redefs [app.config/flags #{:login-with-oidc}]
|
||||
(let [itoken (create-test-invitation-token fixture email)
|
||||
token (create-oidc-register-token email {:invitation-token itoken})]
|
||||
(th/db-delete! :team-invitation
|
||||
{:team-id (:id (:team fixture))
|
||||
:email-to email})
|
||||
(let [out (th/command! {::th/type :register-profile
|
||||
:token token})]
|
||||
(t/is (not (th/success? out)))
|
||||
(t/is (= :validation (-> out :error ex-data :type)))
|
||||
(t/is (= :invalid-token (-> out :error ex-data :code)))
|
||||
(t/is (nil? (th/db-get :profile {:email email}))))))))
|
||||
|
||||
(t/deftest verify-token-redirects-invitation-based-on-member-id
|
||||
(with-redefs [app.config/flags #{:login-with-password}]
|
||||
(let [owner (th/create-profile* 1 {:is-active true})
|
||||
|
||||
@ -270,7 +270,11 @@ PENPOT_OIDC_USER_INFO_SOURCE:
|
||||
__Since version 2.1.2__
|
||||
|
||||
Allows users to register and login with oidc without having to previously
|
||||
register with another method.
|
||||
register with another method. It also works with password login disabled
|
||||
(`disable-login-with-password`): OIDC registration only needs this flag,
|
||||
not password login. An invitation link also works as a substitute for
|
||||
this flag: an invited user can register with OIDC even with both
|
||||
registration flags disabled.
|
||||
|
||||
```bash
|
||||
PENPOT_FLAGS: [...] enable-oidc-registration
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user