mirror of
https://github.com/penpot/penpot.git
synced 2025-08-01 16:38:35 +02:00
🔥 Replace spec with schema on verify-token RPC methods
This commit is contained in:
parent
268f1d40aa
commit
bbc0089166
1 changed files with 22 additions and 22 deletions
|
@ -7,7 +7,7 @@
|
||||||
(ns app.rpc.commands.verify-token
|
(ns app.rpc.commands.verify-token
|
||||||
(:require
|
(:require
|
||||||
[app.common.exceptions :as ex]
|
[app.common.exceptions :as ex]
|
||||||
[app.common.spec :as us]
|
[app.common.schema :as sm]
|
||||||
[app.db :as db]
|
[app.db :as db]
|
||||||
[app.db.sql :as-alias sql]
|
[app.db.sql :as-alias sql]
|
||||||
[app.http.session :as session]
|
[app.http.session :as session]
|
||||||
|
@ -23,21 +23,19 @@
|
||||||
[app.tokens :as tokens]
|
[app.tokens :as tokens]
|
||||||
[app.tokens.spec.team-invitation :as-alias spec.team-invitation]
|
[app.tokens.spec.team-invitation :as-alias spec.team-invitation]
|
||||||
[app.util.services :as sv]
|
[app.util.services :as sv]
|
||||||
[clojure.spec.alpha :as s]))
|
[app.util.time :as dt]))
|
||||||
|
|
||||||
(s/def ::iss keyword?)
|
|
||||||
(s/def ::exp ::us/inst)
|
|
||||||
|
|
||||||
(defmulti process-token (fn [_ _ claims] (:iss claims)))
|
(defmulti process-token (fn [_ _ claims] (:iss claims)))
|
||||||
|
|
||||||
(s/def ::verify-token
|
(def ^:private schema:verify-token
|
||||||
(s/keys :req-un [::token]
|
[:map {:title "verify-token"}
|
||||||
:opt [::rpc/profile-id]))
|
[:token :string]])
|
||||||
|
|
||||||
(sv/defmethod ::verify-token
|
(sv/defmethod ::verify-token
|
||||||
{::rpc/auth false
|
{::rpc/auth false
|
||||||
::doc/added "1.15"
|
::doc/added "1.15"
|
||||||
::doc/module :auth}
|
::doc/module :auth
|
||||||
|
::sm/params schema:verify-token}
|
||||||
[{:keys [::db/pool] :as cfg} {:keys [token] :as params}]
|
[{:keys [::db/pool] :as cfg} {:keys [token] :as params}]
|
||||||
(db/with-atomic [conn pool]
|
(db/with-atomic [conn pool]
|
||||||
(let [claims (tokens/verify (::setup/props cfg) {:token token})
|
(let [claims (tokens/verify (::setup/props cfg) {:token token})
|
||||||
|
@ -131,26 +129,28 @@
|
||||||
|
|
||||||
(assoc member :is-active true)))
|
(assoc member :is-active true)))
|
||||||
|
|
||||||
(s/def ::spec.team-invitation/profile-id ::us/uuid)
|
(def schema:team-invitation-claims
|
||||||
(s/def ::spec.team-invitation/role ::us/keyword)
|
[:map {:title "TeamInvitationClaims"}
|
||||||
(s/def ::spec.team-invitation/team-id ::us/uuid)
|
[:iss :keyword]
|
||||||
(s/def ::spec.team-invitation/member-email ::us/email)
|
[:exp ::dt/instant]
|
||||||
(s/def ::spec.team-invitation/member-id (s/nilable ::us/uuid))
|
[:profile-id ::sm/uuid]
|
||||||
|
[:role teams/schema:role]
|
||||||
|
[:team-id ::sm/uuid]
|
||||||
|
[:member-email ::sm/email]
|
||||||
|
[:member-id {:optional true} ::sm/uuid]])
|
||||||
|
|
||||||
(s/def ::team-invitation-claims
|
(def valid-team-invitation-claims?
|
||||||
(s/keys :req-un [::iss ::exp
|
(sm/lazy-validator schema:team-invitation-claims))
|
||||||
::spec.team-invitation/profile-id
|
|
||||||
::spec.team-invitation/role
|
|
||||||
::spec.team-invitation/team-id
|
|
||||||
::spec.team-invitation/member-email]
|
|
||||||
:opt-un [::spec.team-invitation/member-id]))
|
|
||||||
|
|
||||||
(defmethod process-token :team-invitation
|
(defmethod process-token :team-invitation
|
||||||
[{:keys [conn] :as cfg}
|
[{:keys [conn] :as cfg}
|
||||||
{:keys [::rpc/profile-id token] :as params}
|
{:keys [::rpc/profile-id token] :as params}
|
||||||
{:keys [member-id team-id member-email] :as claims}]
|
{:keys [member-id team-id member-email] :as claims}]
|
||||||
|
|
||||||
(us/verify! ::team-invitation-claims claims)
|
(when-not (valid-team-invitation-claims? claims)
|
||||||
|
(ex/raise :type :validation
|
||||||
|
:code :invalid-invitation-token
|
||||||
|
:hint "invitation token contains unexpected data"))
|
||||||
|
|
||||||
(let [invitation (db/get* conn :team-invitation
|
(let [invitation (db/get* conn :team-invitation
|
||||||
{:team-id team-id :email-to member-email})
|
{:team-id team-id :email-to member-email})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue