You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let response = client.post(endpoint).json(&request).send().await?;
158
+
159
+
if response.status().is_success(){
160
+
let parsed = response
161
+
.json::<DeviceAuthorizationResponse>()
162
+
.await
163
+
.map_err(AuthError::RequestFailed)?;
164
+
if parsed.device_code.trim().is_empty()
165
+
|| parsed.user_code.trim().is_empty()
166
+
|| parsed.verification_uri.trim().is_empty()
167
+
{
168
+
returnErr(AuthError::InvalidResponse(
169
+
"device authorization response is missing required fields".to_string(),
170
+
));
171
+
}
172
+
returnOk(parsed);
173
+
}
174
+
175
+
let oauth_error = parse_oauth_error_response(response).await?;
176
+
Err(map_oauth_terminal_error(
177
+
&oauth_error.error,
178
+
oauth_error.error_description.as_deref(),
179
+
))
180
+
}
181
+
182
+
asyncfnpoll_for_device_token(
183
+
client:&reqwest::Client,
184
+
api_base_url:&str,
185
+
client_id:&str,
186
+
authorization:&DeviceAuthorizationResponse,
187
+
) -> Result<TokenResponse,AuthError>{
188
+
let endpoint = format!("{}/oauth/device/token", api_base_url.trim_end_matches('/'));
189
+
let request = DeviceTokenPollRequest{
190
+
grant_type:DEVICE_CODE_GRANT_TYPE.to_string(),
191
+
device_code: authorization.device_code.clone(),
192
+
client_id: client_id.to_string(),
193
+
};
194
+
195
+
letmut poll_interval_seconds = authorization
196
+
.interval
197
+
.unwrap_or(DEFAULT_DEVICE_POLL_INTERVAL_SECONDS)
198
+
.max(1);
199
+
let max_polls = authorization
200
+
.expires_in
201
+
.saturating_div(poll_interval_seconds)
202
+
.max(1)
203
+
+ 1;
204
+
letmut attempts = 0_u64;
205
+
206
+
loop{
207
+
attempts = attempts.saturating_add(1);
208
+
if attempts > max_polls {
209
+
returnErr(AuthError::Unauthorized(
210
+
"WorkOS device authorization expired before approval completed. Try: run 'sce login' again and complete verification before the code expires.".to_string(),
211
+
));
212
+
}
213
+
214
+
let response = client.post(&endpoint).json(&request).send().await?;
215
+
if response.status().is_success(){
216
+
let token = response
217
+
.json::<TokenResponse>()
218
+
.await
219
+
.map_err(AuthError::RequestFailed)?;
220
+
returnOk(token);
221
+
}
222
+
223
+
let oauth_error = parse_oauth_error_response(response).await?;
0 commit comments