1

I have authorization on python like this:

def return_token():
    return get_oauth2_token()


def disable_stout():
    o_stdout = sys.stdout
    o_file = open(os.devnull, 'w')
    sys.stdout = o_file
    return (o_stdout, o_file)


def enable_stout(o_stdout, o_file):
    o_file.close()
    sys.stdout = o_stdout


def get_oauth2_token():
    CLIENT_ID = '123'
    CLIENT_SECRET = '123'
    SCOPE = \
        'https://www.googleapis.com/auth/plus.login ' + \
        'https://www.googleapis.com/auth/plus.me ' + \
        'https://www.googleapis.com/auth/userinfo.email ' + \
        'https://www.googleapis.com/auth/userinfo.profile ' + \
        'https://mail.google.com/ ' + \
        'https://www.googleapis.com/auth/gmail.readonly ' + \
        'https://www.googleapis.com/auth/gmail.settings.basic'

    REDIRECT_URI = 'http://localhost:8080'

    o_stdout, o_file = disable_stout()

    flow = OAuth2WebServerFlow(
        client_id=CLIENT_ID,
        client_secret=CLIENT_SECRET,
        scope=SCOPE,
        redirect_uri=REDIRECT_URI)

    storage = Storage('creds.data')
    credentials = run_flow(flow, storage)
    enable_stout(o_stdout, o_file)

    print("access_token: %s" % credentials.access_token)
    print("refresh_token: %s" % credentials.refresh_token)


if __name__ == '__main__':
    return_token()

this code work and authorization return access and refresh tokens. All my logic in backend will be work only if i have access and refresh tokens. Developer on front-end use react-native-google-signin library and this library not return refresh token. I have one question: Can i get refresh token by access token ?

nesalexy
  • 848
  • 2
  • 9
  • 30
  • 1
    The refresh token is only returned on the first sign in. Could this be the root issue? https://stackoverflow.com/questions/10827920/not-receiving-google-oauth-refresh-token – nareddyt Jan 09 '19 at 16:58

0 Answers0