def cmd_auth(args):
"""The authentication command
"""
logger.debug('Running command auth')
credentials_storage_path = os.path.join(args.profile_dir, config.oauth_credentials_storage_filename)
credentials_storage = oauth2client.file.Storage(credentials_storage_path)
credentials = credentials_storage.get()
if credentials is None or credentials.invalid:
client_secret_file_handle, client_secret_path = tempfile.mkstemp()
client_secret_fout = os.fdopen(client_secret_file_handle, 'w')
json.dump(config.oauth_client_secret, client_secret_fout)
client_secret_fout.close()
flow = oauth2client.client.flow_from_clientsecrets(client_secret_path,
config.oauth_scopes)
flow.user_agent = config.oauth_application_name
credentials = oauth2client.tools.run_flow(flow, credentials_storage, args)
os.remove(client_secret_path)
return credentials
评论列表
文章目录