-
-
Save si14/121f25077cf842088348 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(s/defn middleware :- mw/CurriedMiddleware | |
[] | |
(p/fnk [] | |
(p/fnk [handler [:info [:annotations auth-scope :- (s/maybe s/Keyword)]] | |
:as annotated-handler] | |
(assoc annotated-handler | |
:handler | |
(p/fnk [datomic-val headers :as req] | |
(if (nil? auth-scope) | |
(handler req) | |
(if-let [auth-header (get headers "Authorization")] | |
(if-let [token (second (re-find bearer-regex auth-header))] | |
(if-let [[token-eid token-scopes-eids] | |
(first (d/q '[:find ?e (distinct ?s) | |
:in $ ?t | |
:where | |
[?e :oauth-token/token ?t] | |
[?e :oauth-token/auth-scopes ?s]] | |
datomic-val token))] | |
(let [token-scopes (set (map (partial d/ident datomic-val) | |
token-scopes-eids))] | |
(if (token-scopes auth-scope) | |
(handler (assoc req :oauth-token-eid token-eid)) | |
(auth-response :no-rights auth-scope))) | |
(auth-response :bad-token)) | |
(auth-response :no-header)) | |
(auth-response :no-header)))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment