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


Python credentials.refresh_token方法代码示例

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


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

示例1: test_from_authorized_user_info

# 需要导入模块: from google.oauth2 import credentials [as 别名]
# 或者: from google.oauth2.credentials import refresh_token [as 别名]
def test_from_authorized_user_info(self):
        info = AUTH_USER_INFO.copy()

        creds = credentials.Credentials.from_authorized_user_info(info)
        assert creds.client_secret == info["client_secret"]
        assert creds.client_id == info["client_id"]
        assert creds.refresh_token == info["refresh_token"]
        assert creds.token_uri == credentials._GOOGLE_OAUTH2_TOKEN_ENDPOINT
        assert creds.scopes is None

        scopes = ["email", "profile"]
        creds = credentials.Credentials.from_authorized_user_info(info, scopes)
        assert creds.client_secret == info["client_secret"]
        assert creds.client_id == info["client_id"]
        assert creds.refresh_token == info["refresh_token"]
        assert creds.token_uri == credentials._GOOGLE_OAUTH2_TOKEN_ENDPOINT
        assert creds.scopes == scopes 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:19,代码来源:test_credentials.py

示例2: test_from_authorized_user_file

# 需要导入模块: from google.oauth2 import credentials [as 别名]
# 或者: from google.oauth2.credentials import refresh_token [as 别名]
def test_from_authorized_user_file(self):
        info = AUTH_USER_INFO.copy()

        creds = credentials.Credentials.from_authorized_user_file(AUTH_USER_JSON_FILE)
        assert creds.client_secret == info["client_secret"]
        assert creds.client_id == info["client_id"]
        assert creds.refresh_token == info["refresh_token"]
        assert creds.token_uri == credentials._GOOGLE_OAUTH2_TOKEN_ENDPOINT
        assert creds.scopes is None

        scopes = ["email", "profile"]
        creds = credentials.Credentials.from_authorized_user_file(
            AUTH_USER_JSON_FILE, scopes
        )
        assert creds.client_secret == info["client_secret"]
        assert creds.client_id == info["client_id"]
        assert creds.refresh_token == info["refresh_token"]
        assert creds.token_uri == credentials._GOOGLE_OAUTH2_TOKEN_ENDPOINT
        assert creds.scopes == scopes 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:21,代码来源:test_credentials.py

示例3: _convert_oauth2_credentials

# 需要导入模块: from google.oauth2 import credentials [as 别名]
# 或者: from google.oauth2.credentials import refresh_token [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

示例4: oauth2callback

# 需要导入模块: from google.oauth2 import credentials [as 别名]
# 或者: from google.oauth2.credentials import refresh_token [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

示例5: _convert_oauth2_credentials

# 需要导入模块: from google.oauth2 import credentials [as 别名]
# 或者: from google.oauth2.credentials import refresh_token [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

示例6: write_credentials

# 需要导入模块: from google.oauth2 import credentials [as 别名]
# 或者: from google.oauth2.credentials import refresh_token [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

示例7: credentials_to_dict

# 需要导入模块: from google.oauth2 import credentials [as 别名]
# 或者: from google.oauth2.credentials import refresh_token [as 别名]
def credentials_to_dict(credentials):
    return {'access_token': credentials.token,
            'refresh_token': credentials.refresh_token,
            'token_uri': credentials.token_uri,
            'client_id': credentials.client_id,
            'client_secret': credentials.client_secret} 
开发者ID:Deeplocal,项目名称:mocktailsmixer,代码行数:8,代码来源:__init__.py

示例8: credentials_from_dict

# 需要导入模块: from google.oauth2 import credentials [as 别名]
# 或者: from google.oauth2.credentials import refresh_token [as 别名]
def credentials_from_dict(credentials, scopes):
    return 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=scopes) 
开发者ID:Deeplocal,项目名称:mocktailsmixer,代码行数:10,代码来源:__init__.py

示例9: make_credentials

# 需要导入模块: from google.oauth2 import credentials [as 别名]
# 或者: from google.oauth2.credentials import refresh_token [as 别名]
def make_credentials(cls):
        return credentials.Credentials(
            token=None,
            refresh_token=cls.REFRESH_TOKEN,
            token_uri=cls.TOKEN_URI,
            client_id=cls.CLIENT_ID,
            client_secret=cls.CLIENT_SECRET,
        ) 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:10,代码来源:test_credentials.py

示例10: test_default_state

# 需要导入模块: from google.oauth2 import credentials [as 别名]
# 或者: from google.oauth2.credentials import refresh_token [as 别名]
def test_default_state(self):
        credentials = self.make_credentials()
        assert not credentials.valid
        # Expiration hasn't been set yet
        assert not credentials.expired
        # Scopes aren't required for these credentials
        assert not credentials.requires_scopes
        # Test properties
        assert credentials.refresh_token == self.REFRESH_TOKEN
        assert credentials.token_uri == self.TOKEN_URI
        assert credentials.client_id == self.CLIENT_ID
        assert credentials.client_secret == self.CLIENT_SECRET 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:14,代码来源:test_credentials.py

示例11: test_refresh_no_refresh_token

# 需要导入模块: from google.oauth2 import credentials [as 别名]
# 或者: from google.oauth2.credentials import refresh_token [as 别名]
def test_refresh_no_refresh_token(self):
        request = mock.create_autospec(transport.Request)
        credentials_ = credentials.Credentials(token=None, refresh_token=None)

        with pytest.raises(exceptions.RefreshError, match="necessary fields"):
            credentials_.refresh(request)

        request.assert_not_called() 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:10,代码来源:test_credentials.py

示例12: test_apply_with_quota_project_id

# 需要导入模块: from google.oauth2 import credentials [as 别名]
# 或者: from google.oauth2.credentials import refresh_token [as 别名]
def test_apply_with_quota_project_id(self):
        creds = credentials.Credentials(
            token="token",
            refresh_token=self.REFRESH_TOKEN,
            token_uri=self.TOKEN_URI,
            client_id=self.CLIENT_ID,
            client_secret=self.CLIENT_SECRET,
            quota_project_id="quota-project-123",
        )

        headers = {}
        creds.apply(headers)
        assert headers["x-goog-user-project"] == "quota-project-123" 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:15,代码来源:test_credentials.py

示例13: test_apply_with_no_quota_project_id

# 需要导入模块: from google.oauth2 import credentials [as 别名]
# 或者: from google.oauth2.credentials import refresh_token [as 别名]
def test_apply_with_no_quota_project_id(self):
        creds = credentials.Credentials(
            token="token",
            refresh_token=self.REFRESH_TOKEN,
            token_uri=self.TOKEN_URI,
            client_id=self.CLIENT_ID,
            client_secret=self.CLIENT_SECRET,
        )

        headers = {}
        creds.apply(headers)
        assert "x-goog-user-project" not in headers 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:14,代码来源:test_credentials.py

示例14: test_with_quota_project

# 需要导入模块: from google.oauth2 import credentials [as 别名]
# 或者: from google.oauth2.credentials import refresh_token [as 别名]
def test_with_quota_project(self):
        creds = credentials.Credentials(
            token="token",
            refresh_token=self.REFRESH_TOKEN,
            token_uri=self.TOKEN_URI,
            client_id=self.CLIENT_ID,
            client_secret=self.CLIENT_SECRET,
            quota_project_id="quota-project-123",
        )

        new_creds = creds.with_quota_project("new-project-456")
        assert new_creds.quota_project_id == "new-project-456"
        headers = {}
        creds.apply(headers)
        assert "x-goog-user-project" in headers 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:17,代码来源:test_credentials.py

示例15: test_credentials_with_scopes_requested_refresh_success

# 需要导入模块: from google.oauth2 import credentials [as 别名]
# 或者: from google.oauth2.credentials import refresh_token [as 别名]
def test_credentials_with_scopes_requested_refresh_success(
        self, unused_utcnow, refresh_grant
    ):
        scopes = ["email", "profile"]
        token = "token"
        expiry = _helpers.utcnow() + datetime.timedelta(seconds=500)
        grant_response = {"id_token": mock.sentinel.id_token}
        refresh_grant.return_value = (
            # Access token
            token,
            # New refresh token
            None,
            # Expiry,
            expiry,
            # Extra data
            grant_response,
        )

        request = mock.create_autospec(transport.Request)
        creds = credentials.Credentials(
            token=None,
            refresh_token=self.REFRESH_TOKEN,
            token_uri=self.TOKEN_URI,
            client_id=self.CLIENT_ID,
            client_secret=self.CLIENT_SECRET,
            scopes=scopes,
        )

        # Refresh credentials
        creds.refresh(request)

        # Check jwt grant call.
        refresh_grant.assert_called_with(
            request,
            self.TOKEN_URI,
            self.REFRESH_TOKEN,
            self.CLIENT_ID,
            self.CLIENT_SECRET,
            scopes,
        )

        # Check that the credentials have the token and expiry
        assert creds.token == token
        assert creds.expiry == expiry
        assert creds.id_token == mock.sentinel.id_token
        assert creds.has_scopes(scopes)

        # Check that the credentials are valid (have a token and are not
        # expired.)
        assert creds.valid 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:52,代码来源:test_credentials.py


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