chrisjshull / homebridge-nest

Nest plugin for HomeBridge
699 stars 112 forks source link

403 Forbidden #610

Closed gelato closed 1 year ago

gelato commented 1 year ago

Is this working still? Lately i can't authenticate with any method available - getting 403 always:

data: '<!doctype html>403403 Forbidden' }, isAxiosError: true, toJSON: [Function: toJSON], status: 403 } [4/22/2023, 3:31:34 AM] [Nest] Could not authenticate with Nest (code 403). Retrying in 15 second(s).

adriancable commented 1 year ago

@gelato - are you able to post the complete error output here (not just the end of it)? Feel free to scramble some characters on any lines that contain authentication tokens (but don't change the structure). Thank you!

gelato commented 1 year ago

Sure!

[4/22/2023, 4:16:52 AM] [Nest] Could not authenticate with Nest (code 403). Retrying in 15 second(s).
Error: Request failed with status code 403
    at createError (/homebridge/node_modules/homebridge-nest/node_modules/axios/lib/core/createError.js:16:15)
    at settle (/homebridge/node_modules/homebridge-nest/node_modules/axios/lib/core/settle.js:17:12)
    at IncomingMessage.handleStreamEnd (/homebridge/node_modules/homebridge-nest/node_modules/axios/lib/adapters/http.js:269:11)
    at IncomingMessage.emit (node:events:525:35)
    at endReadableNT (node:internal/streams/readable:1359:12)
    at processTicksAndRejections (node:internal/process/task_queues:82:21) {
  config: {
    url: 'https://home.nest.com/session',
    method: 'get',
    headers: {
      Accept: 'application/json, text/plain, */*',
      Authorization: 'Basic TOKEN',
      'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36',
      cookie: 'G_ENABLED_IDPS=google; eu_cookie_accepted=1; viewer-volume=0.5; cztoken=TOKEN'
    },
    transformRequest: [ [Function: transformRequest] ],
    transformResponse: [ [Function: transformResponse] ],
    timeout: 40000,
    adapter: [Function: httpAdapter],
    xsrfCookieName: 'XSRF-TOKEN',
    xsrfHeaderName: 'X-XSRF-TOKEN',
    maxContentLength: -1,
    maxBodyLength: -1,
    validateStatus: [Function: validateStatus],
    transitional: {
      silentJSONParsing: true,
      forcedJSONParsing: true,
      clarifyTimeoutError: false
    },
    data: undefined
  },
  request: <ref *1> ClientRequest {
    _events: [Object: null prototype] {
      abort: [Function (anonymous)],
      aborted: [Function (anonymous)],
      connect: [Function (anonymous)],
      error: [Function (anonymous)],
      socket: [Function (anonymous)],
      timeout: [Function (anonymous)],
      finish: [Function: requestOnFinish]
    },
    _eventsCount: 7,
    _maxListeners: undefined,
    outputData: [],
    outputSize: 0,
    writable: true,
    destroyed: false,
    _last: true,
    chunkedEncoding: false,
    shouldKeepAlive: false,
    maxRequestsOnConnectionReached: false,
    _defaultKeepAlive: true,
    useChunkedEncodingByDefault: false,
    sendDate: false,
    _removedConnection: false,
    _removedContLen: false,
    _removedTE: false,
    strictContentLength: false,
    _contentLength: 0,
    _hasBody: true,
    _trailer: '',
    finished: true,
    _headerSent: true,
    _closed: false,
    socket: TLSSocket {
      _tlsOptions: [Object],
      _secureEstablished: true,
      _securePending: false,
      _newSessionPending: false,
      _controlReleased: true,
      secureConnecting: false,
      _SNICallback: null,
      servername: 'home.nest.com',
      alpnProtocol: false,
      authorized: true,
      authorizationError: null,
      encrypted: true,
      _events: [Object: null prototype],
      _eventsCount: 10,
      connecting: false,
      _hadError: false,
      _parent: null,
      _host: 'home.nest.com',
      _closeAfterHandlingError: false,
      _readableState: [ReadableState],
      _maxListeners: undefined,
      _writableState: [WritableState],
      allowHalfOpen: false,
      _sockname: null,
      _pendingData: null,
      _pendingEncoding: '',
      server: undefined,
      _server: null,
      ssl: [TLSWrap],
      _requestCert: true,
      _rejectUnauthorized: true,
      parser: null,
      _httpMessage: [Circular *1],
      timeout: 40000,
      [Symbol(res)]: [TLSWrap],
      [Symbol(verified)]: true,
      [Symbol(pendingSession)]: null,
      [Symbol(async_id_symbol)]: 12031,
      [Symbol(kHandle)]: [TLSWrap],
      [Symbol(lastWriteQueueSize)]: 0,
      [Symbol(timeout)]: Timeout {
        _idleTimeout: 40000,
        _idlePrev: [TimersList],
        _idleNext: [TimersList],
        _idleStart: 3014413,
        _onTimeout: [Function: bound ],
        _timerArgs: undefined,
        _repeat: null,
        _destroyed: false,
        [Symbol(refed)]: false,
        [Symbol(kHasPrimitive)]: false,
        [Symbol(asyncId)]: 12039,
        [Symbol(triggerId)]: 12034
      },
      [Symbol(kBuffer)]: null,
      [Symbol(kBufferCb)]: null,
      [Symbol(kBufferGen)]: null,
      [Symbol(kCapture)]: false,
      [Symbol(kSetNoDelay)]: false,
      [Symbol(kSetKeepAlive)]: false,
      [Symbol(kSetKeepAliveInitialDelay)]: 0,
      [Symbol(kBytesRead)]: 0,
      [Symbol(kBytesWritten)]: 0,
      [Symbol(connect-options)]: [Object]
    },
    _header: 'GET /session HTTP/1.1\r\n' +
      'Accept: application/json, text/plain, */*\r\n' +
      'Authorization: Basic TOKEN\r\n' +
      'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36\r\n' +
      'cookie: G_ENABLED_IDPS=google; eu_cookie_accepted=1; viewer-volume=0.5; cztoken=TOKEN\r\n' +
      'Host: home.nest.com\r\n' +
      'Connection: close\r\n' +
      '\r\n',
    _keepAliveTimeout: 0,
    _onPendingData: [Function: nop],
    agent: Agent {
      _events: [Object: null prototype],
      _eventsCount: 2,
      _maxListeners: undefined,
      defaultPort: 443,
      protocol: 'https:',
      options: [Object: null prototype],
      requests: [Object: null prototype] {},
      sockets: [Object: null prototype],
      freeSockets: [Object: null prototype] {},
      keepAliveMsecs: 1000,
      keepAlive: false,
      maxSockets: Infinity,
      maxFreeSockets: 256,
      scheduling: 'lifo',
      maxTotalSockets: Infinity,
      totalSocketCount: 1,
      maxCachedSessions: 100,
      _sessionCache: [Object],
      [Symbol(kCapture)]: false
    },
    socketPath: undefined,
    method: 'GET',
    maxHeaderSize: undefined,
    insecureHTTPParser: undefined,
    path: '/session',
    _ended: true,
    res: IncomingMessage {
      _readableState: [ReadableState],
      _events: [Object: null prototype],
      _eventsCount: 3,
      _maxListeners: undefined,
      socket: [TLSSocket],
      httpVersionMajor: 1,
      httpVersionMinor: 1,
      httpVersion: '1.1',
      complete: true,
      rawHeaders: [Array],
      rawTrailers: [],
      aborted: false,
      upgrade: false,
      url: '',
      method: null,
      statusCode: 403,
      statusMessage: 'Forbidden',
      client: [TLSSocket],
      _consuming: false,
      _dumped: false,
      req: [Circular *1],
      responseUrl: 'https://home.nest.com/session',
      redirects: [],
      [Symbol(kCapture)]: false,
      [Symbol(kHeaders)]: [Object],
      [Symbol(kHeadersCount)]: 10,
      [Symbol(kTrailers)]: null,
      [Symbol(kTrailersCount)]: 0
    },
    aborted: false,
    timeoutCb: null,
    upgradeOrConnect: false,
    parser: null,
    maxHeadersCount: null,
    reusedSocket: false,
    host: 'home.nest.com',
    protocol: 'https:',
    _redirectable: Writable {
      _writableState: [WritableState],
      _events: [Object: null prototype],
      _eventsCount: 3,
      _maxListeners: undefined,
      _options: [Object],
      _ended: true,
      _ending: true,
      _redirectCount: 0,
      _redirects: [],
      _requestBodyLength: 0,
      _requestBodyBuffers: [],
      _onNativeResponse: [Function (anonymous)],
      _currentRequest: [Circular *1],
      _currentUrl: 'https://home.nest.com/session',
      _timeout: null,
      [Symbol(kCapture)]: false
    },
    [Symbol(kCapture)]: false,
    [Symbol(kBytesWritten)]: 0,
    [Symbol(kEndCalled)]: true,
    [Symbol(kNeedDrain)]: false,
    [Symbol(corked)]: 0,
    [Symbol(kOutHeaders)]: [Object: null prototype] {
      accept: [Array],
      authorization: [Array],
      'user-agent': [Array],
      cookie: [Array],
      host: [Array]
    },
    [Symbol(errored)]: null,
    [Symbol(kUniqueHeaders)]: null
  },
  response: {
    status: 403,
    statusText: 'Forbidden',
    headers: {
      'content-length': '134',
      'content-type': 'text/html; charset=UTF-8',
      date: 'Sat, 22 Apr 2023 02:17:11 GMT',
      'alt-svc': 'clear',
      connection: 'close'
    },
    config: {
      url: 'https://home.nest.com/session',
      method: 'get',
      headers: [Object],
      transformRequest: [Array],
      transformResponse: [Array],
      timeout: 40000,
      adapter: [Function: httpAdapter],
      xsrfCookieName: 'XSRF-TOKEN',
      xsrfHeaderName: 'X-XSRF-TOKEN',
      maxContentLength: -1,
      maxBodyLength: -1,
      validateStatus: [Function: validateStatus],
      transitional: [Object],
      data: undefined
    },
    request: <ref *1> ClientRequest {
      _events: [Object: null prototype],
      _eventsCount: 7,
      _maxListeners: undefined,
      outputData: [],
      outputSize: 0,
      writable: true,
      destroyed: false,
      _last: true,
      chunkedEncoding: false,
      shouldKeepAlive: false,
      maxRequestsOnConnectionReached: false,
      _defaultKeepAlive: true,
      useChunkedEncodingByDefault: false,
      sendDate: false,
      _removedConnection: false,
      _removedContLen: false,
      _removedTE: false,
      strictContentLength: false,
      _contentLength: 0,
      _hasBody: true,
      _trailer: '',
      finished: true,
      _headerSent: true,
      _closed: false,
      socket: [TLSSocket],
      _header: 'GET /session HTTP/1.1\r\n' +
        'Accept: application/json, text/plain, */*\r\n' +
        'Authorization: Basic TOKEN\r\n' +
        'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36\r\n' +
        'cookie: G_ENABLED_IDPS=google; eu_cookie_accepted=1; viewer-volume=0.5; cztoken=TOKEN\r\n' +
        'Host: home.nest.com\r\n' +
        'Connection: close\r\n' +
        '\r\n',
      _keepAliveTimeout: 0,
      _onPendingData: [Function: nop],
      agent: [Agent],
      socketPath: undefined,
      method: 'GET',
      maxHeaderSize: undefined,
      insecureHTTPParser: undefined,
      path: '/session',
      _ended: true,
      res: [IncomingMessage],
      aborted: false,
      timeoutCb: null,
      upgradeOrConnect: false,
      parser: null,
      maxHeadersCount: null,
      reusedSocket: false,
      host: 'home.nest.com',
      protocol: 'https:',
      _redirectable: [Writable],
      [Symbol(kCapture)]: false,
      [Symbol(kBytesWritten)]: 0,
      [Symbol(kEndCalled)]: true,
      [Symbol(kNeedDrain)]: false,
      [Symbol(corked)]: 0,
      [Symbol(kOutHeaders)]: [Object: null prototype],
      [Symbol(errored)]: null,
      [Symbol(kUniqueHeaders)]: null
    },
    data: '<!doctype html><meta charset="utf-8"><meta name=viewport content="width=device-width, initial-scale=1"><title>403</title>403 Forbidden'
  },
  isAxiosError: true,
  toJSON: [Function: toJSON],
  status: 403
}
[4/22/2023, 4:17:11 AM] [Nest] Could not authenticate with Nest (code 403). Retrying in 15 second(s).
adriancable commented 1 year ago

Hmm, not sure. Are you using a Nest account or a Google account? If the latter, can you try using an incognito window and following the instructions in the README again to get a fresh set of cookies?

gelato commented 1 year ago

Strangely result is the same on both Nest and Google cookies. I've refreshed cookies 3 times - result is always the same. Even tried to use VPN, thinking that this might be some kind of networking issue with IPs banned, but it didn't help.

adriancable commented 1 year ago

Can you explain what you mean when you say “same on both Nest and Google cookies”? Either you have a Nest account or a Google account, and there is one method described in the README for Nest accounts and one for Google accounts. If you use the Nest account method when you have a Google account, it won’t work. If you use the Google account method when you have a Nest account, it won’t work.

So first please use the correct method for your account type. Then if it still doesn’t work, please post your complete config.json. Scramble a few characters in the cookies/tokens if you wish, but please don’t remove them completely as I need to check the structure. I suspect they’re not being put in the config correctly.

blaine07 commented 1 year ago

My "Google" login Nest setup recently quit working too:

{ "platform": "Nest", "name": "Nest", "googleAuth": { "issueToken": "https://accounts.google.com/o/oauth2/iframerpc?action=issueToken&response_type=token%20id_token&login_hint=AJDLj6LQu-SMCQLMJfOUep6S7tCeW9Ffd6yoiDEsdfdsfdsfdsfdkmdtyfghjdrthjszdtfgt7R0aAaPkRvY9QzumzePGsaBzpQ&client_id=733249279899-44tchle2kaa9afr5v9ov7jbuojfr9lrq.apps.googleusercontent.com&origin=https%3A%2F%2Fhome.nest.com&scope=openid%20profile%20email%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fnest-account&ss_domain=https%3A%2F%2Fhome.nest.com&include_granted_scopes=true", "cookies": "Secure-3PSID=Rgh3Xqe8BV6Dxc_Gy0f3MbCeweXDlStDj3KTuHgaQHEHMAsFDUjGwDXVziXIKlVlSx2oQQ.; __Host-3PLSID=o.chat.google.com|o.mail.google.com|o.play.google.com|o.remotedesktop.google.com|s.youtube:Rgh3XjeovDS1D58peHU4EV2ggHOpF_UpjRBLz_zQc6CWS7kQd7_xrtiZ1ztqZJbGvBnArA.; Secure-3PAPISID=X7NQm-CcY4Ztxf8n/AlxQwAHT3mHgf5flD; 1P_JAR=2022-12-19-23; NID=511=gQkLp-vCOZuvmcp4KX_jaQ-auSjj3-u63AUhrXwndnV7XcirtyrtyrtyrthfghL25NgDtBkhGm_P8CgZclhukG6xEmWlbkRhUrPDxBAre_kkYis-MLpGjTek6axFK_JTj0tA1JDZ28slimthCwhxHh7bv43BEsHWMtsaMYuAJobgdS_2rAEXN8KTX6cyqTIfZrv7F26-zijmmyfYaMxe8b3fnSwqrWkeZAWoDn1gX06m82Li2QwBV6Gn4jouuiEgIimSYG9JavveqQxCuBHULHb6tslf2365V70BNzcOKDskrOSvAdRlNZOk; LSOLH=_SVIEO3etPnzhvwCGA8iP01BRURIZl9xbUlOYzFrQ254dExMejZXYm9hM3FZQ2M3Wnp6UHY2N182TnpnWm9jSWxMalZnOHdhNHhIZHVaWQ:27858264:6a49; __Secure-3PSIDCC=AIKkIs2KPx_40EpNxxjnl5n0Pzp5lC3xYGR-pxnD76fkifikCETDoey19jGx1rf3ZPXWL76LFgg" }, "fanDurationMinutes": 15 }

Altered a few characters. Previously to switching to "Google" account I had used "Nest account". I had a different plugin running with old nest credentials, copied them to this Nest plugin and works fine.

TLDR; the "google account" type login with cookie and toke is NOT working for some reason recently.

adriancable commented 1 year ago

I just tried following my own instructions in the README to get a fresh set of cookies (in a Chrome incognito window). It works fine.

From what you posted, some of the cookies seem to be missing. Maybe you are not copying/pasting the whole string, or maybe you are not picking the last oauth2/iframe call in the Network tab.

blaine07 commented 1 year ago

I just tried following my own instructions in the README to get a fresh set of cookies (in a Chrome incognito window). It works fine.

From what you posted, some of the cookies seem to be missing. Maybe you are not copying/pasting the whole string, or maybe you are not picking the last oauth2/iframe call in the Network tab.

Is it possible the "Hoobs Nest Sidecar" chrome plugin isn't getting all the information? I admittedly didn't manually gather everything; just used plugin. But it sure didn't work...

adriancable commented 1 year ago

I'm sorry, I don't have any connection with the "Hoobs Nest Sidecar" (and I'd never even heard of it until I Googled it just now). I can only help you if you have issues following my own instructions for getting the cookies for this plug-in, in the README.

kostecky commented 1 year ago

I'm having the same issue. This just started happening a few weeks ago. My nest integration is dead on homebridge and no matter how many times I refresh the issueToken and cookies, it doesn't work anymore. Was working for many months prior.

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.