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


Python credentials.with_scopes_if_required方法代码示例

本文整理汇总了Python中google.auth.credentials.with_scopes_if_required方法的典型用法代码示例。如果您正苦于以下问题:Python credentials.with_scopes_if_required方法的具体用法?Python credentials.with_scopes_if_required怎么用?Python credentials.with_scopes_if_required使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在google.auth.credentials的用法示例。


在下文中一共展示了credentials.with_scopes_if_required方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_create_scoped_if_required_scoped

# 需要导入模块: from google.auth import credentials [as 别名]
# 或者: from google.auth.credentials import with_scopes_if_required [as 别名]
def test_create_scoped_if_required_scoped():
    unscoped_credentials = RequiresScopedCredentialsImpl()
    scoped_credentials = credentials.with_scopes_if_required(
        unscoped_credentials, ["one", "two"]
    )

    assert scoped_credentials is not unscoped_credentials
    assert not scoped_credentials.requires_scopes
    assert scoped_credentials.has_scopes(["one", "two"]) 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:11,代码来源:test_credentials.py

示例2: test_create_scoped_if_required_not_scopes

# 需要导入模块: from google.auth import credentials [as 别名]
# 或者: from google.auth.credentials import with_scopes_if_required [as 别名]
def test_create_scoped_if_required_not_scopes():
    unscoped_credentials = CredentialsImpl()
    scoped_credentials = credentials.with_scopes_if_required(
        unscoped_credentials, ["one", "two"]
    )

    assert scoped_credentials is unscoped_credentials 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:9,代码来源:test_credentials.py

示例3: _make_delegated_credentials

# 需要导入模块: from google.auth import credentials [as 别名]
# 或者: from google.auth.credentials import with_scopes_if_required [as 别名]
def _make_delegated_credentials(credentials, user_email, scopes):
    """Make delegated credentials.

    Allows a service account to impersonate the user passed in `user_email`,
    using a restricted set of scopes.

    Args:
        credentials (service_account.Credentials): The service account credentials.
        user_email (str): The email for the user to impersonate.
        scopes (list): A list of scopes.

    Returns:
        service_account.Credentials: The delegated credentials
    """
    request = requests.Request()
    credentials = with_scopes_if_required(credentials, _TOKEN_SCOPE)
    credentials.refresh(request)
    email = credentials.service_account_email
    signer = iam.Signer(
        request,
        credentials,
        email)
    return service_account.Credentials(
        signer,
        email,
        _TOKEN_URI,
        scopes=scopes,
        subject=user_email) 
开发者ID:GoogleCloudPlatform,项目名称:professional-services,代码行数:30,代码来源:auth.py

示例4: get_delegated_credential

# 需要导入模块: from google.auth import credentials [as 别名]
# 或者: from google.auth.credentials import with_scopes_if_required [as 别名]
def get_delegated_credential(delegated_account, scopes):
    """Build delegated credentials required for accessing the gsuite APIs.

    Args:
        delegated_account (str): The account to delegate the service account to
            use.
        scopes (list): The list of required scopes for the service account.

    Returns:
        service_account.Credentials: Credentials as built by
        google.oauth2.service_account.
    """
    request = requests.Request()

    # Get the "bootstrap" credentials that will be used to talk to the IAM
    # API to sign blobs.
    bootstrap_credentials, _ = google.auth.default()

    bootstrap_credentials = with_scopes_if_required(
        bootstrap_credentials,
        list(CLOUD_SCOPES))

    # Refresh the boostrap credentials. This ensures that the information about
    # this account, notably the email, is populated.
    bootstrap_credentials.refresh(request)

    # Create an IAM signer using the bootstrap credentials.
    signer = iam.Signer(request,
                        bootstrap_credentials,
                        bootstrap_credentials.service_account_email)

    # Create OAuth 2.0 Service Account credentials using the IAM-based signer
    # and the bootstrap_credential's service account email.
    delegated_credentials = service_account.Credentials(
        signer, bootstrap_credentials.service_account_email, _TOKEN_URI,
        scopes=scopes, subject=delegated_account)

    return delegated_credentials 
开发者ID:forseti-security,项目名称:forseti-security,代码行数:40,代码来源:api_helpers.py


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