def get_authorized_http_object(scopes):
'''JWT credentials authorization.
:param scopes: the authorization scope to be requested
:return: httplib2.Http object, with authorized credentials
'''
def _build_jwt_dict():
jwt_dict = {key.replace(JWT_NAMESPACE, '').lower(): settings[key]
for key in settings
if key.startswith(JWT_NAMESPACE)}
# Handle newlines in private key
if 'private_key' in jwt_dict:
jwt_dict['private_key'] = \
jwt_dict['private_key'].replace('\\n', '\n')
jwt_dict['PROJECT_ID'] = settings['GOOGLE_API_PROJECT_ID']
return jwt_dict
credentials = ServiceAccountCredentials.from_json_keyfile_dict(
_build_jwt_dict(), scopes=scopes)
return credentials.authorize(httplib2.Http())
评论列表
文章目录