extensions/github-authentication/src/githubServer.ts/GitHubServer/waitForDeviceCodeAccessToken
class GitHubServer:	private async waitForDeviceCodeAccessToken(
		json: IGitHubDeviceCodeResponse,
		token: vscode.CancellationToken
	): Promise<string> {

		const refreshTokenUri = `https://github.com/login/oauth/access_token?client_id=${CLIENT_ID}&device_code=${json.device_code}&grant_type=urn:ietf:params:oauth:grant-type:device_code`;

		// Try for 2 minutes
		const attempts = 120 / json.interval;
		for (let i = 0; i < attempts; i++) {
			await new Promise(resolve => setTimeout(resolve, json.interval * 1000));
			if (token.isCancellationRequested) {
				throw new Error('Cancelled');
			}
			let accessTokenResult;
			try {
				accessTokenResult = await fetch(refreshTokenUri, {
					method: 'POST',
					headers: {
						Accept: 'application/json'
					}
				});
			} catch {
				continue;
			}

			if (!accessTokenResult.ok) {
				continue;
			}

			const accessTokenJson = await accessTokenResult.json();

			if (accessTokenJson.error === 'authorization_pending') {
				continue;
			}

			if (accessTokenJson.error) {
				throw new Error(accessTokenJson.error_description);
			}

			return accessTokenJson.access_token;
		}

		throw new Error('Cancelled');
	}