Beispiel #1
0
def authenticate():
    global headers, authenticated
    configPath = os.path.abspath(os.path.join(os.path.dirname(__file__), '../config'))

    configFilePath = '%s/config.txt' % configPath
    configParser = auth.grab()

    old_token = {}
    old_token['access_token'] = configParser.get('fitbit', 'access_token')
    old_token['refresh_token'] = configParser.get('fitbit', 'refresh_token')

    fit = fitbit.Fitbit()
    try:
        creds = fit.RefAccessToken(old_token)

        # write in the new creds
        configParser.set('fitbit', 'access_token', creds['access_token'])
        configParser.set('fitbit', 'refresh_token', creds['refresh_token'])
        with open(configFilePath, 'wb') as configFile:
            configParser.write(configFile)

        # set the auth headers to be used
        headers = {'Authorization': 'Bearer ' + creds['access_token']}
        authenticated = True
    except Exception:
        headers = {}
        authenticated = False
        pass
Beispiel #2
0
def grabKey(keyName, envName='', param='key'):
    env = os.environ

    if keyName.upper() in env:
        KEY = env[keyName.upper()]
    elif envName.upper() in env:
        KEY = env[envName.upper()]
    else:
        configParser = auth.grab()
        KEY = configParser.get(keyName.lower(), param)
    return KEY