当前位置: 首页>>代码示例>>Python>>正文


Python credentials.scopes方法代码示例

本文整理汇总了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 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:25,代码来源:_oauth2client.py

示例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) 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:20,代码来源:main.py

示例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')) 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:26,代码来源:main.py

示例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 
开发者ID:fniephaus,项目名称:alfred-gmail,代码行数:24,代码来源:_oauth2client.py

示例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) 
开发者ID:tensorflow,项目名称:tensorboard,代码行数:27,代码来源:auth.py

示例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"] 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:11,代码来源:test__default.py

示例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"] 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:9,代码来源:test__default.py

示例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) 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:10,代码来源:test__default.py

示例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,
    ) 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:17,代码来源:_oauth2client.py

示例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) 
开发者ID:fniephaus,项目名称:alfred-gmail,代码行数:16,代码来源:_oauth2client.py

示例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
    ) 
开发者ID:tensorflow,项目名称:tensorboard,代码行数:15,代码来源:auth.py


注:本文中的google.oauth2.credentials.scopes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。