|
73 | 73 | :http-client (client/merge-with-global-http-client {}) |
74 | 74 | :as :json})] |
75 | 75 | (if-let [token (:token body)] |
76 | | - {:api-key token |
77 | | - :expires-at (:expires_at body)} |
| 76 | + (cond-> {:api-key token |
| 77 | + :expires-at (:expires_at body)} |
| 78 | + (get-in body [:endpoints :api]) (assoc :api-url (get-in body [:endpoints :api]))) |
78 | 79 | (throw (ex-info (format "Error on copilot login: %s" body) |
79 | 80 | {:status status |
80 | 81 | :body body}))))) |
|
94 | 95 | (get-in @db* [:auth "github-copilot" :step]))) |
95 | 96 | (let [result (try |
96 | 97 | (let [access-token (oauth-access-token provider-settings device-code) |
97 | | - {:keys [api-key expires-at]} (oauth-renew-token provider-settings access-token)] |
| 98 | + token-data (oauth-renew-token provider-settings access-token)] |
98 | 99 | (swap! db* update-in [:auth "github-copilot"] merge |
99 | | - {:step :login/done |
100 | | - :access-token access-token |
101 | | - :api-key api-key |
102 | | - :expires-at expires-at}) |
| 100 | + (assoc token-data |
| 101 | + :step :login/done |
| 102 | + :access-token access-token)) |
103 | 103 | (f.providers/sync-and-notify! "github-copilot" db* messenger metrics) |
104 | 104 | :done) |
105 | 105 | (catch Exception e |
|
131 | 131 | (defmethod f.login/login-step ["github-copilot" :login/waiting-user-confirmation] [{:keys [db* provider config send-msg!] :as ctx}] |
132 | 132 | (let [provider-settings (get-in config [:providers provider]) |
133 | 133 | access-token (oauth-access-token provider-settings (get-in @db* [:auth provider :device-code])) |
134 | | - {:keys [api-key expires-at]} (oauth-renew-token provider-settings access-token)] |
135 | | - (swap! db* update-in [:auth provider] merge {:step :login/done |
136 | | - :access-token access-token |
137 | | - :api-key api-key |
138 | | - :expires-at expires-at}) |
| 134 | + token-data (oauth-renew-token provider-settings access-token)] |
| 135 | + (swap! db* update-in [:auth provider] merge |
| 136 | + (assoc token-data :step :login/done :access-token access-token)) |
139 | 137 | (f.login/login-done! ctx) |
140 | 138 | (send-msg! (format "\nMake sure to enable the model you want to use at: %s/settings/copilot/features" |
141 | 139 | (github-base-url provider-settings))))) |
142 | 140 |
|
143 | 141 | (defmethod f.login/login-step ["github-copilot" :login/renew-token] [{:keys [db* provider config] :as ctx}] |
144 | 142 | (let [provider-settings (get-in config [:providers provider]) |
145 | 143 | access-token (get-in @db* [:auth provider :access-token]) |
146 | | - {:keys [api-key expires-at]} (oauth-renew-token provider-settings access-token)] |
147 | | - (swap! db* update-in [:auth provider] merge {:api-key api-key |
148 | | - :expires-at expires-at}) |
| 144 | + token-data (oauth-renew-token provider-settings access-token)] |
| 145 | + (swap! db* update-in [:auth provider] merge token-data) |
149 | 146 | (f.login/login-done! ctx :silent? true :skip-models-sync? true))) |
0 commit comments