     private var redirectURI: String?
     private var baseURL: String?
     private var APIBaseURL: String?
+    private var isWaitingToToken: Bool = false
     
     // Keys
     let accessTokenKey = "accessToken"

    
    public func getTokenFromDevice(code: DeviceCode?, completionHandler: ProgressCompletionHandler?) {
        guard
            let clientID = clientID,
            let clientSecret = clientSecret,
            let deviceCode = code else {
                completionHandler?(.fail(0))
                return

            return
        }
        request.httpBody = body
        self.isWaitingToToken = true
        
        DispatchQueue.global().async {
            var i = 1
            while self.isWaitingToToken {
                if i >= deviceCode.expires_in {
                    self.isWaitingToToken = false
                    continue
                }
                self.sendReques(request: request, count: i) { result in
                    completionHandler?(result)
                    switch result {
                    case .success:
                        self.isWaitingToToken = false
                    case .fail(let progress):
                        if progress == 0 {
                            self.isWaitingToToken = false
                        }
                    }
                }
                i += 1
                sleep(1)
            }
        }
    }
    
    private func sendReques(request:URLRequest, count:Int, completionHandler: ProgressCompletionHandler?) {
