The essence of the task: Send an ajax request with authorization data

  site.com/oauth2/device?grant_type=device_code&client_id=code& client_secret = secret 

If the request is successful, we get a response.

  {code: 'code', user_code: 'CODE', interval: 10, expires_in: 300} 

Every n seconds (taken from the interval) send ajax request with the received data. Until the user enters user_code on the site.

  site.com/oauth2/device?grant_type=device_token&client_id=code& client_secret = secret & code = code 

If everything is correct, we get access token

How to wait for a response from the first request to send a second?

  • Forget about the interval, in Promise wait for the query to be executed, then start the timeout with the same query. - user207618
  • @Other and more? Preferably with an example. - Aslan Sosmakov
  • Ajax so promise returns. - Jean-Claude

0