本文整理汇总了Python中google.oauth2.credentials.scopes方法的典型用法代码示例。如果您正苦于以下问题:Python credentials.scopes方法的具体用法?Python credentials.scopes怎么用?Python credentials.scopes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类google.oauth2.credentials
的用法示例。
在下文中一共展示了credentials.scopes方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _convert_oauth2_credentials
# 需要导入模块: from google.oauth2 import credentials [as 别名]
# 或者: from google.oauth2.credentials import scopes [as 别名]
def _convert_oauth2_credentials(credentials):
"""Converts to :class:`google.oauth2.credentials.Credentials`.
Args:
credentials (Union[oauth2client.client.OAuth2Credentials,
oauth2client.client.GoogleCredentials]): The credentials to
convert.
Returns:
google.oauth2.credentials.Credentials: The converted credentials.
"""
new_credentials = google.oauth2.credentials.Credentials(
token=credentials.access_token,
refresh_token=credentials.refresh_token,
token_uri=credentials.token_uri,
client_id=credentials.client_id,
client_secret=credentials.client_secret,
scopes=credentials.scopes,
)
new_credentials._expires = credentials.token_expiry
return new_credentials
示例2: authorize
# 需要导入模块: from google.oauth2 import credentials [as 别名]
# 或者: from google.oauth2.credentials import scopes [as 别名]
def authorize():
# Create a flow instance to manage the OAuth 2.0 Authorization Grant Flow
# steps.
flow = google_auth_oauthlib.flow.Flow.from_client_secrets_file(
CLIENT_SECRETS_FILENAME, scopes=SCOPES)
flow.redirect_uri = flask.url_for('oauth2callback', _external=True)
authorization_url, state = flow.authorization_url(
# This parameter enables offline access which gives your application
# an access token and a refresh token for the user's credentials.
access_type='offline',
# This parameter enables incremental auth.
include_granted_scopes='true')
# Store the state in the session so that the callback can verify the
# authorization server response.
flask.session['state'] = state
return flask.redirect(authorization_url)
示例3: oauth2callback
# 需要导入模块: from google.oauth2 import credentials [as 别名]
# 或者: from google.oauth2.credentials import scopes [as 别名]
def oauth2callback():
# Specify the state when creating the flow in the callback so that it can
# verify the authorization server response.
state = flask.session['state']
flow = google_auth_oauthlib.flow.Flow.from_client_secrets_file(
CLIENT_SECRETS_FILENAME, scopes=SCOPES, state=state)
flow.redirect_uri = flask.url_for('oauth2callback', _external=True)
# Use the authorization server's response to fetch the OAuth 2.0 tokens.
authorization_response = flask.request.url
flow.fetch_token(authorization_response=authorization_response)
# Store the credentials in the session.
credentials = flow.credentials
flask.session['credentials'] = {
'token': credentials.token,
'refresh_token': credentials.refresh_token,
'token_uri': credentials.token_uri,
'client_id': credentials.client_id,
'client_secret': credentials.client_secret,
'scopes': credentials.scopes
}
return flask.redirect(flask.url_for('index'))
示例4: _convert_oauth2_credentials
# 需要导入模块: from google.oauth2 import credentials [as 别名]
# 或者: from google.oauth2.credentials import scopes [as 别名]
def _convert_oauth2_credentials(credentials):
"""Converts to :class:`google.oauth2.credentials.Credentials`.
Args:
credentials (Union[oauth2client.client.OAuth2Credentials,
oauth2client.client.GoogleCredentials]): The credentials to
convert.
Returns:
google.oauth2.credentials.Credentials: The converted credentials.
"""
new_credentials = google.oauth2.credentials.Credentials(
token=credentials.access_token,
refresh_token=credentials.refresh_token,
token_uri=credentials.token_uri,
client_id=credentials.client_id,
client_secret=credentials.client_secret,
scopes=credentials.scopes)
new_credentials._expires = credentials.token_expiry
return new_credentials
示例5: write_credentials
# 需要导入模块: from google.oauth2 import credentials [as 别名]
# 或者: from google.oauth2.credentials import scopes [as 别名]
def write_credentials(self, credentials):
"""Writes a `google.oauth2.credentials.Credentials` to the store."""
if not isinstance(credentials, google.oauth2.credentials.Credentials):
raise TypeError(
"Cannot write credentials of type %s" % type(credentials)
)
if self._credentials_filepath is None:
return
# Make the credential file private if not on Windows; on Windows we rely on
# the default user config settings directory being private since we don't
# have a straightforward way to make an individual file private.
private = os.name != "nt"
util.make_file_with_directories(
self._credentials_filepath, private=private
)
data = {
"refresh_token": credentials.refresh_token,
"token_uri": credentials.token_uri,
"client_id": credentials.client_id,
"client_secret": credentials.client_secret,
"scopes": credentials.scopes,
"type": "authorized_user",
}
with open(self._credentials_filepath, "w") as f:
json.dump(data, f)
示例6: test_load_credentials_from_file_authorized_user_cloud_sdk_with_scopes
# 需要导入模块: from google.oauth2 import credentials [as 别名]
# 或者: from google.oauth2.credentials import scopes [as 别名]
def test_load_credentials_from_file_authorized_user_cloud_sdk_with_scopes():
with pytest.warns(UserWarning, match="Cloud SDK"):
credentials, project_id = _default.load_credentials_from_file(
AUTHORIZED_USER_CLOUD_SDK_FILE,
scopes=["https://www.google.com/calendar/feeds"],
)
assert isinstance(credentials, google.oauth2.credentials.Credentials)
assert project_id is None
assert credentials.scopes == ["https://www.google.com/calendar/feeds"]
示例7: test_load_credentials_from_file_service_account_with_scopes
# 需要导入模块: from google.oauth2 import credentials [as 别名]
# 或者: from google.oauth2.credentials import scopes [as 别名]
def test_load_credentials_from_file_service_account_with_scopes():
credentials, project_id = _default.load_credentials_from_file(
SERVICE_ACCOUNT_FILE, scopes=["https://www.google.com/calendar/feeds"]
)
assert isinstance(credentials, service_account.Credentials)
assert project_id == SERVICE_ACCOUNT_FILE_DATA["project_id"]
assert credentials.scopes == ["https://www.google.com/calendar/feeds"]
示例8: test_default_scoped
# 需要导入模块: from google.oauth2 import credentials [as 别名]
# 或者: from google.oauth2.credentials import scopes [as 别名]
def test_default_scoped(with_scopes, unused_get):
scopes = ["one", "two"]
credentials, project_id = _default.default(scopes=scopes)
assert credentials == with_scopes.return_value
assert project_id == mock.sentinel.project_id
with_scopes.assert_called_once_with(mock.sentinel.credentials, scopes)
示例9: _convert_appengine_app_assertion_credentials
# 需要导入模块: from google.oauth2 import credentials [as 别名]
# 或者: from google.oauth2.credentials import scopes [as 别名]
def _convert_appengine_app_assertion_credentials(credentials):
"""Converts to :class:`google.auth.app_engine.Credentials`.
Args:
credentials (oauth2client.contrib.app_engine.AppAssertionCredentials):
The credentials to convert.
Returns:
google.oauth2.service_account.Credentials: The converted credentials.
"""
# pylint: disable=invalid-name
return google.auth.app_engine.Credentials(
scopes=_helpers.string_to_scopes(credentials.scope),
service_account_id=credentials.service_account_id,
)
示例10: _convert_appengine_app_assertion_credentials
# 需要导入模块: from google.oauth2 import credentials [as 别名]
# 或者: from google.oauth2.credentials import scopes [as 别名]
def _convert_appengine_app_assertion_credentials(credentials):
"""Converts to :class:`google.auth.app_engine.Credentials`.
Args:
credentials (oauth2client.contrib.app_engine.AppAssertionCredentials):
The credentials to convert.
Returns:
google.oauth2.service_account.Credentials: The converted credentials.
"""
# pylint: disable=invalid-name
return google.auth.app_engine.Credentials(
scopes=_helpers.string_to_scopes(credentials.scope),
service_account_id=credentials.service_account_id)
示例11: build_installed_app_flow
# 需要导入模块: from google.oauth2 import credentials [as 别名]
# 或者: from google.oauth2.credentials import scopes [as 别名]
def build_installed_app_flow(client_config):
"""Returns a `CustomInstalledAppFlow` for the given config.
Args:
client_config (Mapping[str, Any]): The client configuration in the Google
client secrets format.
Returns:
CustomInstalledAppFlow: the constructed flow.
"""
return CustomInstalledAppFlow.from_client_config(
client_config, scopes=OPENID_CONNECT_SCOPES
)