Skip to content

Commit

Permalink
hopefully update to use keycloak client to fetch IP, session ID, and …
Browse files Browse the repository at this point in the history
…login time to send down to apps
  • Loading branch information
ianmcorvidae committed Dec 10, 2024
1 parent 8b8e3e5 commit a12fafc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/terrain/clients/apps/raw.clj
Original file line number Diff line number Diff line change
Expand Up @@ -1277,8 +1277,8 @@
:content-type :json}))))

(defn record-login
[ip-address user-agent]
(let [params (remove-nil-values {:ip-address ip-address :user-agent user-agent})]
[ip-address session-id login-time]
(let [params (remove-nil-values {:ip-address ip-address :session-id session-id :login-time login-time})]
(:body
(client/post (apps-url "users" "login")
(disable-redirects
Expand Down
12 changes: 9 additions & 3 deletions src/terrain/services/bootstrap.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[slingshot.slingshot :refer [try+]]
[terrain.auth.user-attributes :refer [current-user]]
[terrain.clients.apps.raw :as apps-client]
[terrain.clients.keycloak.admin :as kc-client]
[terrain.clients.data-info :as data-info-client]
[terrain.services.user-prefs :as prefs]
[terrain.util.service :as service]))
Expand Down Expand Up @@ -33,9 +34,14 @@
{:error (str (:throwable &throw-context))})))

(defn- get-login-session
[ip-address user-agent]
[username]
(trap-bootstrap-request
#(select-keys (apps-client/record-login ip-address user-agent) [:login_time :auth_redirect])))
#(let [kc-resp (kc-client/get-user-session-by-username username)
current-session (first kc-resp) ;; TODO: choose most recent start/access using our known client ID
]
(select-keys (apps-client/record-login (:ipAddress current-session nil)
(:id current-session nil)
(:start current-session nil)) [:login_time :auth_redirect]))))

(defn- get-apps-info
[]
Expand All @@ -60,7 +66,7 @@
[ip-address user-agent]
(assertions/assert-valid user-agent "Missing or empty request parameter: user-agent")
(let [{user :shortUsername :keys [email firstName lastName username]} current-user
login-session (future (get-login-session ip-address user-agent))
login-session (future (get-login-session username))
apps-info (future (get-apps-info))
data-info (future (get-user-data-info user))
preferences (future (get-user-prefs username))]
Expand Down

0 comments on commit a12fafc

Please sign in to comment.