getoauthtoken.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:Deploy_XXNET_Server 作者: jzp820927 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号