def handle_noargs(self, **unused_options):
"""Perform an OAuth 2.0 oob flow.
After the flow completes, instructions are provided to manually store the
OAuth2 refresh_token in the project settings file.
"""
flow = rdbms_googleapi.GetFlow()
self.stdout.write('\nGo to the following link in your browser:\n%s\n\n' %
flow.step1_get_authorize_url('oob'))
accepted = 'n'
while accepted.lower() == 'n':
accepted = raw_input('Have you authorized me? (y/n) ')
code = raw_input('What is the verification code? ').strip()
try:
credential = flow.step2_exchange(code)
except client.FlowExchangeError:
raise base.CommandError('The authentication has failed.')
self.stdout.write(
'\nAdd your OAuth refresh token (%s) as an "OAUTH2_SECRET" parameter to'
' your database OPTIONS. For example:\n' % credential.refresh_token)
self.stdout.write("""
DATABASES = {
'default': {
'ENGINE': 'google.storage.speckle.python.django.backend',
'INSTANCE': 'examplecom:instance',
'NAME': 'dbname',
'OPTIONS': {
'OAUTH2_SECRET': '%s',
}
}
}\n""" % credential.refresh_token)
评论列表
文章目录