Ejemplo n.º 1
0
    def refresh_callback(new_credentials):
        """Updates credentials.

        Params:
            new_credentials: withings_api.Credentials2
        """
        logging.debug('Withings creds refresh for: %s', service.key)
        creds_dict = create_creds_dict(new_credentials)
        Service.update_credentials(service, creds_dict)
Ejemplo n.º 2
0
def _oauth(request: flask.Request, user: Entity, dest: str):
    code = request.args.get('code')
    service = Service.get(SERVICE_NAME, parent=user.key)
    client = stravalib.client.Client()
    creds = client.exchange_code_for_token(
        client_id=config.strava_creds['client_id'],
        client_secret=config.strava_creds['client_secret'],
        code=code,
    )
    Service.update_credentials(service, dict(creds))
    task_util.sync_service(service)
    return flask.redirect(config.devserver_url + dest)
Ejemplo n.º 3
0
def redirect(user):
    service = Service.get(SERVICE_NAME, parent=user.key)

    code = flask.request.args.get('code')
    dest = flask.request.args.get('dest', '')

    auth = create_auth(callback_uri=get_callback_uri(dest))

    creds_dict = create_creds_dict(auth.get_credentials(code))
    Service.update_credentials(service, creds_dict)

    task_util.sync_service(service)

    return flask.redirect(config.devserver_url + dest)
Ejemplo n.º 4
0
 def _refresh_access_token(self):
     if self._service['credentials'].get('refresh_token') is None:
         logging.warning(
             'Cannot refresh_access_token for %s, no refresh_token',
             self._service.key,
         )
         return False
     new_credentials = self._client.refresh_access_token(
         client_id=config.strava_creds['client_id'],
         client_secret=config.strava_creds['client_secret'],
         refresh_token=self._service['credentials']['refresh_token'],
     )
     Service.update_credentials(self._service, dict(new_credentials))
     self._client.access_token = self._service['credentials'][
         'access_token']
     return True
Ejemplo n.º 5
0
def redirect(user):
    service = Service.get(SERVICE_NAME, parent=user.key)

    code = flask.request.args.get('code')
    dest = flask.request.args.get('dest', '')

    auth_client = fitbit.FitbitOauth2Client(
        client_id=config.fitbit_creds['client_id'],
        client_secret=config.fitbit_creds['client_secret'],
        redirect_uri=get_redirect_uri(dest),
    )
    creds = auth_client.fetch_access_token(code)

    Service.update_credentials(service, creds)

    task_util.sync_service(service)

    return flask.redirect(config.devserver_url + dest)
Ejemplo n.º 6
0
def _oauth(user: Entity, dest: str, redirect_uri: str):
    """Step 2. Stores credentials."""
    service = Service.get(SERVICE_NAME, parent=user.key)

    state = flask.session['state']
    flow = google_auth_oauthlib.flow.Flow.from_client_config(
        config.gcp_web_creds, scopes=SCOPES, state=state)
    flow.redirect_uri = redirect_uri

    authorization_response = flask.request.url
    logging.debug('auth_response: %s', authorization_response)
    flow.fetch_token(authorization_response=authorization_response)
    creds = _credentials_to_dict(flow.credentials)
    logging.debug('creds: %s', creds)

    Service.update_credentials(service, creds)

    task_util.sync_service(Service.get(SERVICE_NAME, parent=user.key))
    return flask.redirect(config.devserver_url + dest)
Ejemplo n.º 7
0
 def refresh_callback(session_state):
     logging.debug('Garmin creds refresh for: %s', service.key)
     Service.update_credentials(service, {'session_state': session_state})
Ejemplo n.º 8
0
 def refresh_callback(new_credentials):
     logging.debug('Fitbit creds refresh for: %s', service.key)
     Service.update_credentials(service, new_credentials)