working on reauth.

This commit is contained in:
2022-03-29 19:50:13 -07:00
parent 17fde0dd16
commit 17e6b283df
4 changed files with 135 additions and 18 deletions

View File

@@ -54,5 +54,24 @@
{:status 400
:headers {"Content-Type" "application/edn"}
:body (pr-str {:message (.getMessage e)
:error (.toString e)})})))
(POST "/reauthenticate/:id" {:keys [identity] {:keys [id]} :route-params
data :edn-params}
(assert-admin identity)
(try
{:status 200
:headers {"Content-Type" "application/edn"}
:body (pr-str (yodlee/reauthenticate-and-recache
(-> (:client-id data)
Long/parseLong
d-clients/get-by-id
:client/code)
(Long/parseLong id)
(dissoc data :client-id )))}
(catch Exception e
(log/error e)
{:status 500
:headers {"Content-Type" "application/edn"}
:body (pr-str {:message (.getMessage e)
:error (.toString e)})}))))
wrap-secure))

View File

@@ -330,17 +330,20 @@
(update-provider-account id)
(refresh-provider-account id))
(defn reauthenticate [pa data]
(let [cob-session (login-cobrand)]
(try
(doto (-> (str (:yodlee2-base-url env) "/providerAccounts?providerAccountIds=" pa)
(defn reauthenticate [client-code pa data]
(println client-code)
(try
(doto (-> (str (:yodlee2-base-url env) "/providerAccounts?providerAccountIds=" pa)
(client/put (merge {:headers (merge base-headers {"Authorization" (auth-header cob-session)})
:body (json/write-str data)
:as :json}
other-config)))
log/info)
(refresh-provider-account pa)
(catch Exception e
(log/error e)))))
(client/put (doto (merge {:headers (merge base-headers {"Authorization" (auth-header (login-user (client-code->login client-code)))})
:body (json/write-str data)
:as :json}
other-config)
clojure.pprint/pprint)))
log/info)
(catch Exception e
(log/error e))) )
(defn reauthenticate-and-recache [client-code pa data]
(reauthenticate client-code pa data)
(refresh-provider-account client-code pa))

View File

@@ -1,4 +1,99 @@
(ns auto-ap.views.pages.admin.yodlee2.form)
(ns auto-ap.views.pages.admin.yodlee2.form
(:require [auto-ap.views.components.modal :as modal]
[auto-ap.status :as status]
[auto-ap.forms :as forms]
[re-frame.core :as re-frame]
[auto-ap.views.utils :refer [->$ action-cell-width date->str with-user dispatch-event]]))
(defn form []
[:div])
(re-frame/reg-sub
::can-submit
(fn [db]
true))
(re-frame/reg-event-fx
::saved
(forms/triggers-stop ::form)
(fn [{:keys [db]} [_ {:keys [edit-user]}]]
{:dispatch [::modal/modal-closed]}))
(re-frame/reg-event-fx
::saving
[with-user (forms/in-form [::form])]
(fn [{:keys [user db]} [_ ]]
(let [provider-account-id (:id (:data db))]
{:http {:token user
:method :post
:owns-state {:single ::form}
:headers {"Content-Type" "application/edn"}
:uri (str "/api/yodlee2/reauthenticate/" provider-account-id)
:body {:client-id (:client-id (:data db))
"loginForm"
{"row"
(->> db
:data
:login
(sort-by (fn [[k v]] k))
(map second)
(map (fn [row]
{"field"
(mapv (fn [[k v]]
{"id" k
"value" v})
row)})))}
"field"
(mapv (fn [[k v]]
{"id" k
"value" v})
(-> db :data :mfa))}
:on-success [::saved]}})))
(def reauthenticate-form (forms/vertical-form {:submit-event [::saving]
:change-event [::forms/change ::form]
:can-submit [::can-submit]
:id ::form}))
(defn form [{:keys [provider-account]}]
(let [{error :error account-data :data } @(re-frame/subscribe [::forms/form [::form (:id provider-account)]])
{:keys [form-inline field error-notification submit-button]} reauthenticate-form
]
(form-inline {:title "Reauthenticate"}
[:<>
(error-notification)
(doall
(for [[row i] (map vector (-> account-data :provider-account :loginForm last :row) (range))
f (:field row)
:let [options (map :optionValue (:option f))]]
^{:key (:id f)}
[:div
(field (:label row)
[:input.input {:type "text" :field [:login i (:id f)]}])
(if (seq options)
[:ul
(for [o options]
^{:key o}
[:li [:pre o]])])]))
(doall
(for [f (-> account-data :provider-account :field)]
^{:key (:id f)}
(field (:label f)
[:input.input {:type "text" :mfa [:form (:id f)] :value (-> f :field first :value)}])))])))
(re-frame/reg-event-fx
::reauthenticate-start
(fn [{:keys [db]} [_ provider-account client-id]]
(println provider-account)
{:db (-> db
(forms/start-form ::form {:id (:id provider-account)
:client-id client-id
:provider-account provider-account}))
:dispatch [::modal/modal-requested {:title (str "Reauthenticate " (:id provider-account))
:body [form {:provider-account provider-account}]
:cancel? false
:confirm {:value "Reauthenticate"
:status-from [::status/single ::form]
:class "is-primary"
:on-click (dispatch-event [::saving])
:close-event [::status/completed ::form]}}]}))

View File

@@ -4,7 +4,7 @@
[auto-ap.views.components.buttons :as buttons]
[auto-ap.views.components.grid :as grid]
[auto-ap.views.components.modal :as modal]
[auto-ap.views.pages.admin.users.form :as form]
[auto-ap.views.pages.admin.yodlee2.form :as form]
[auto-ap.views.utils :refer [->$ action-cell-width date->str with-user dispatch-event]]
[re-frame.core :as re-frame]
[auto-ap.forms :as forms]))
@@ -107,7 +107,7 @@
[:li (:name a) " - " (:number a) [:div.tag (->$ (:available-balance a))]])]]
[grid/cell {}
[:div.buttons
[buttons/fa-icon {:event [::form/editing c]
[buttons/fa-icon {:event [::form/reauthenticate-start c (:id (:client c))]
:icon "fa-pencil"}]
[buttons/fa-icon {:event [::request-refresh (:id c) (:id (:client c))]
:class (status/class-for (get statuses (:id c)))