Skip to content

Issue with refreshtoken #63

@pdev77

Description

@pdev77

Hi
I'm simply using pyhiveapi to pull data from hive periodically. It has worked fine for months - but now they have introduced mandatory 2fa - I would have to 2fa at every data pull once the session["IdToken"] expires.
This I guess is what the session["RefreshToken"] is for - but I cant figure how to use it.
I've tried
newTokens = hive_auth.refresh_token(authData['AuthenticationResult']['IdToken'])
but it throws
botocore.errorfactory.NotAuthorizedException: An error occurred (NotAuthorizedException) when calling the InitiateAuth operation: Invalid Refresh Token.

I'm definitely passing the right token - but if anyone can tell what is a miss it would be appreciated!

full sample code

import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning

requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
import json
import sys
import argparse
import pyhiveapi as Hive
import time

requests.packages.urllib3.disable_warnings()

tokens = {}
hive_auth = Hive.Auth(args.username, args.password)

authData = hive_auth.login()

if authData.get("ChallengeName") == "SMS_MFA":
    code = input("Enter your 2FA code: ")
    authData = hive_auth.sms_2fa(code, authData)

if "AuthenticationResult" in authData:
    session = authData["AuthenticationResult"]
    tokens.update({"token": session["IdToken"]})
    tokens.update({"refreshToken": session["RefreshToken"]})
    tokens.update({"accessToken": session["AccessToken"]})

time.sleep(10)

newTokens = hive_auth.refresh_token(authData['AuthenticationResult']['RefreshToken'])

if "AuthenticationResult" in newTokens:
    session = newTokens["AuthenticationResult"]
    tokens.update({"token": session["IdToken"]})
    tokens.update({"refreshToken": session["RefreshToken"]})
    tokens.update({"accessToken": session["AccessToken"]})

print (tokens["token"])
print (tokens["refreshToken"])

exit()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions