* add a component for hangouts * add a notify component for hangouts * add an extra message as title * add support to listen to all conversations hangouts has * move hangouts to package and add parameter documentation * update .coveragerc and requirements_all.txt * makes linter happy again * bugfix * add conversations parameter to command words * Move the resolution of conversation names to conversations in own a function * typo * rename group of exclusion form 'id' to 'id or name' * refactoring and use config_flow * makes linter happy again * remove unused imports * fix not working regex commands * fix translations * cleanup * remove step_init * remove logging entry * clean up events * move constant * remove unsed import * add new files to .converagerc * isort imports * add hangouts_utils to ignored packages * upadte doc and format * fix I/O not in executor jon * rename SERVICE_UPDATE_USERS_AND_CONVERSATIONS to SERVICE_UPDATE * move EVENT_HANGOUTS_{CONNECTED,DISCONNECTED} to dispatcher * add config flow tests * Update tox.ini
81 lines
1.9 KiB
Python
81 lines
1.9 KiB
Python
"""Utils needed for Google Hangouts."""
|
|
|
|
from hangups import CredentialsPrompt, GoogleAuthError, RefreshTokenCache
|
|
|
|
|
|
class Google2FAError(GoogleAuthError):
|
|
"""A Google authentication request failed."""
|
|
|
|
|
|
class HangoutsCredentials(CredentialsPrompt):
|
|
"""Google account credentials.
|
|
|
|
This implementation gets the user data as params.
|
|
"""
|
|
|
|
def __init__(self, email, password, pin=None):
|
|
"""Google account credentials.
|
|
|
|
:param email: Google account email address.
|
|
:param password: Google account password.
|
|
:param pin: Google account verification code.
|
|
"""
|
|
self._email = email
|
|
self._password = password
|
|
self._pin = pin
|
|
|
|
def get_email(self):
|
|
"""Return email.
|
|
|
|
:return: Google account email address.
|
|
"""
|
|
return self._email
|
|
|
|
def get_password(self):
|
|
"""Return password.
|
|
|
|
:return: Google account password.
|
|
"""
|
|
return self._password
|
|
|
|
def get_verification_code(self):
|
|
"""Return the verification code.
|
|
|
|
:return: Google account verification code.
|
|
"""
|
|
if self._pin is None:
|
|
raise Google2FAError()
|
|
return self._pin
|
|
|
|
def set_verification_code(self, pin):
|
|
"""Set the verification code.
|
|
|
|
:param pin: Google account verification code.
|
|
"""
|
|
self._pin = pin
|
|
|
|
|
|
class HangoutsRefreshToken(RefreshTokenCache):
|
|
"""Memory-based cache for refresh token."""
|
|
|
|
def __init__(self, token):
|
|
"""Memory-based cache for refresh token.
|
|
|
|
:param token: Initial refresh token.
|
|
"""
|
|
super().__init__("")
|
|
self._token = token
|
|
|
|
def get(self):
|
|
"""Get cached refresh token.
|
|
|
|
:return: Cached refresh token.
|
|
"""
|
|
return self._token
|
|
|
|
def set(self, refresh_token):
|
|
"""Cache a refresh token.
|
|
|
|
:param refresh_token: Refresh token to cache.
|
|
"""
|
|
self._token = refresh_token
|