costastf / locationsharinglib

A library to retrieve coordinates from an google account that has been shared locations of other accounts.
MIT License
170 stars 29 forks source link

Single-factor authentication failing #58

Closed SteveDinn closed 5 years ago

SteveDinn commented 5 years ago

Sometime in the last few days, it seems like something has changed on Google's end that prevents locationsharinglib from successfully authenticating. I'm using the locationsharinglib 3.0.11 with the following small shell script to refresh my cookie file:

#!/srv/hass/bin/python
# -*- coding: utf-8 -*-

import os
import sys

scriptFolder = os.path.dirname(os.path.realpath(__file__))
username = sys.argv[1]
password = sys.argv[2]
currentFolder = os.getcwd()
cookies_file = scriptFolder + "/" + sys.argv[3]

if os.path.isfile(cookies_file):
  os.remove(cookies_file)

from locationsharinglib import Service
service = Service(username, password, cookies_file)

for person in service.get_shared_people():
   print(person)
   print("\n")

It also fails in the exactly the same manner from Home Assistant 0.87.1. All was working last week, the last time I restarted HA.

$ refresh-google-maps-cookies.py 'user@gmail.com' '**********' '.google_maps_location_sharing.cookies'

Traceback (most recent call last):
  File "/home/hass/config/refresh-google-maps-cookies.py", line 21, in <module>
    service = Service(username, password, cookies_file)
  File "/srv/hass/lib/python3.5/site-packages/locationsharinglib/locationsharinglib.py", line 366, in __init__
    cookies_file=cookies_file)
  File "/srv/hass/lib/python3.5/site-packages/locationsharinglib/locationsharinglib.py", line 225, in __init__
    self._authenticate()
  File "/srv/hass/lib/python3.5/site-packages/locationsharinglib/locationsharinglib.py", line 263, in _authenticate
    self._submit_password()
  File "/srv/hass/lib/python3.5/site-packages/locationsharinglib/locationsharinglib.py", line 306, in _submit_password
    raise InvalidCredentials(body)
locationsharinglib.locationsharinglibexceptions.InvalidCredentials:

I don't want to post all the response, because it contains personal identifying information, but the response contains "type: FIRST_AUTH_FACTOR" (I only have single-factor authentication), and "INCORRECT_ANSWER_ENTERED". I'm sure I have the correct password. I'm able to login successfully via a browser. If any other parts of the response are pertinent, I can provide them.

woutersmit commented 5 years ago

+1 Experiencing this as well.

pilos011 commented 5 years ago

+1 Experiencing this as well.

danieledwardgeorgehitchcock commented 5 years ago

+1 Experiencing this as well - This issue doesn't seem to be localised to HomeAssistant. I have created a pipenv and experience the same error when executing a service call

costastf commented 5 years ago

This is part of the wackamole game and it really is not fun. I invested some time looking into a solution to interactively log in the service and retrieve the cookies and then provide the cookies to the library. I will try to find that piece of code and report here until next weekend. Until then just copy over your cookies from a browser session as described in https://github.com/costastf/locationsharinglib/issues/50#issuecomment-448939141

costastf commented 5 years ago

I will not be trying to fix this issue in the current code base. Please use the above mentioned work around and be a bit patient until I find some time to build a tool to help with that process.

SteveDinn commented 5 years ago

Thanks for spending your time doing this. Just wanted to let you know that your work is appreciated! It helps make sure my porch lights are on when I come home at night :)

Oh, and if it matters, I'm in Canada, so I guess this issue just started for us.

costastf commented 5 years ago

Thanks a lot for letting me know, it really helps! I will try my best to sort this out as soon as possible.

costastf commented 5 years ago

I have removed the authentication part from locationsharinglib and uploaded version 4 with those changes. I have made a proof of concept project that drives a browser via selenium and saves the cookies in a compatible with locationsharinglib format. If anyone wants to try out the POC and very crud version because they are feeling adventurous you can follow the documentation at the end of the page https://github.com/costastf/mapscookiegettercli/blob/initial-usability/USAGE.rst . This is heavily a work in progress and only works for chrome currently, tested only on Mac (but i guess linux should also work) so please do not start creating issues just yet, unless you also want to contribute. I am planing to clean it up and and make it nicer during the upcoming weekends. I am hoping to have a somewhat properly working version out after the coming weekend supporting chrome for all latest version of Mac, Linux and Windows. Of course if anyone is interested in helping out, all help is welcome!