(wait: Duration.Duration)
| 238 | |
| 239 | function poll(http: HttpClient.HttpClient, server: string, deviceCode: string, interval: Duration.Duration) { |
| 240 | const loop = (wait: Duration.Duration): Effect.Effect<Credential.OAuth, unknown> => |
| 241 | Effect.gen(function* () { |
| 242 | yield* Effect.sleep(wait) |
| 243 | const result = yield* post( |
| 244 | http, |
| 245 | `${server}/auth/device/token`, |
| 246 | { |
| 247 | grant_type: "urn:ietf:params:oauth:grant-type:device_code", |
| 248 | device_code: deviceCode, |
| 249 | client_id: clientID, |
| 250 | }, |
| 251 | DeviceToken, |
| 252 | false, |
| 253 | ) |
| 254 | if ("access_token" in result) return yield* credential(http, server, result) |
| 255 | if (result.error === "authorization_pending") return yield* loop(wait) |
| 256 | if (result.error === "slow_down") { |
| 257 | return yield* loop(Duration.sum(wait, Duration.seconds(5))) |
| 258 | } |
| 259 | return yield* Effect.fail(new Error(`Device authorization failed: ${result.error}`)) |
| 260 | }) |
| 261 | return loop(interval) |
| 262 | } |
| 263 |
no test coverage detected