|
@@ -134,14 +134,33 @@
|
|
|
(and (<= 400 (:status resp))
|
|
(and (<= 400 (:status resp))
|
|
|
(> 500 (:status resp)))
|
|
(> 500 (:status resp)))
|
|
|
;; invalid refresh-token
|
|
;; invalid refresh-token
|
|
|
- (clear-tokens)
|
|
|
|
|
|
|
+ (do
|
|
|
|
|
+ (prn :debug :refresh-token-failed
|
|
|
|
|
+ :status (:status resp)
|
|
|
|
|
+ :user-id (user-uuid)
|
|
|
|
|
+ :refresh-token refresh-token
|
|
|
|
|
+ :resp resp)
|
|
|
|
|
+ (state/pub-event! [:instrument {:type :refresh-token-failed
|
|
|
|
|
+ :payload {:status (:status resp)
|
|
|
|
|
+ :user-id (user-uuid)
|
|
|
|
|
+ :refresh-token refresh-token
|
|
|
|
|
+ :resp resp}}])
|
|
|
|
|
+ (when (and (= 400 (:status resp))
|
|
|
|
|
+ (= (:error (:body resp)) "invalid_grant"))
|
|
|
|
|
+ (clear-tokens)))
|
|
|
|
|
|
|
|
;; e.g. api return 500, server internal error
|
|
;; e.g. api return 500, server internal error
|
|
|
;; we shouldn't clear tokens if they aren't expired yet
|
|
;; we shouldn't clear tokens if they aren't expired yet
|
|
|
;; the `refresh-tokens-loop` will retry soon
|
|
;; the `refresh-tokens-loop` will retry soon
|
|
|
(and (not (http/unexceptional-status? (:status resp)))
|
|
(and (not (http/unexceptional-status? (:status resp)))
|
|
|
(not (-> (state/get-auth-id-token) parse-jwt expired?)))
|
|
(not (-> (state/get-auth-id-token) parse-jwt expired?)))
|
|
|
- nil ; do nothing
|
|
|
|
|
|
|
+ (do
|
|
|
|
|
+ (prn :debug :refresh-token-failed
|
|
|
|
|
+ :status (:status resp)
|
|
|
|
|
+ :body (:body resp)
|
|
|
|
|
+ :error-code (:error-code resp)
|
|
|
|
|
+ :error-text (:error-text resp))
|
|
|
|
|
+ nil) ; do nothing
|
|
|
|
|
|
|
|
(not (http/unexceptional-status? (:status resp)))
|
|
(not (http/unexceptional-status? (:status resp)))
|
|
|
(notification/show! "exceptional status when refresh-token" :warning true)
|
|
(notification/show! "exceptional status when refresh-token" :warning true)
|
|
@@ -217,14 +236,15 @@
|
|
|
|
|
|
|
|
(defn <ensure-id&access-token
|
|
(defn <ensure-id&access-token
|
|
|
[]
|
|
[]
|
|
|
- (go
|
|
|
|
|
- (when (or (nil? (state/get-auth-id-token))
|
|
|
|
|
- (-> (state/get-auth-id-token) parse-jwt almost-expired-or-expired?))
|
|
|
|
|
- (debug/pprint (str "refresh tokens... " (tc/to-string (t/now))))
|
|
|
|
|
- (<! (<refresh-id-token&access-token))
|
|
|
|
|
- (when (or (nil? (state/get-auth-id-token))
|
|
|
|
|
- (-> (state/get-auth-id-token) parse-jwt expired?))
|
|
|
|
|
- (ex-info "empty or expired token and refresh failed" {:anom :expired-token})))))
|
|
|
|
|
|
|
+ (let [id-token (state/get-auth-id-token)]
|
|
|
|
|
+ (go
|
|
|
|
|
+ (when (or (nil? id-token)
|
|
|
|
|
+ (-> id-token parse-jwt almost-expired-or-expired?))
|
|
|
|
|
+ (debug/pprint (str "refresh tokens... " (tc/to-string (t/now))))
|
|
|
|
|
+ (<! (<refresh-id-token&access-token))
|
|
|
|
|
+ (when (or (nil? (state/get-auth-id-token))
|
|
|
|
|
+ (-> (state/get-auth-id-token) parse-jwt expired?))
|
|
|
|
|
+ (ex-info "empty or expired token and refresh failed" {:anom :expired-token}))))))
|
|
|
|
|
|
|
|
(defn <user-uuid
|
|
(defn <user-uuid
|
|
|
[]
|
|
[]
|