當前位置: 首頁>>代碼示例>>Python>>正文


Python credentials.client_secret方法代碼示例

本文整理匯總了Python中google.oauth2.credentials.client_secret方法的典型用法代碼示例。如果您正苦於以下問題:Python credentials.client_secret方法的具體用法?Python credentials.client_secret怎麽用?Python credentials.client_secret使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在google.oauth2.credentials的用法示例。


在下文中一共展示了credentials.client_secret方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_from_authorized_user_info

# 需要導入模塊: from google.oauth2 import credentials [as 別名]
# 或者: from google.oauth2.credentials import client_secret [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 client_secret [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: test_to_json

# 需要導入模塊: from google.oauth2 import credentials [as 別名]
# 或者: from google.oauth2.credentials import client_secret [as 別名]
def test_to_json(self):
        info = AUTH_USER_INFO.copy()
        creds = credentials.Credentials.from_authorized_user_info(info)

        # Test with no `strip` arg
        json_output = creds.to_json()
        json_asdict = json.loads(json_output)
        assert json_asdict.get("token") == creds.token
        assert json_asdict.get("refresh_token") == creds.refresh_token
        assert json_asdict.get("token_uri") == creds.token_uri
        assert json_asdict.get("client_id") == creds.client_id
        assert json_asdict.get("scopes") == creds.scopes
        assert json_asdict.get("client_secret") == creds.client_secret

        # Test with a `strip` arg
        json_output = creds.to_json(strip=["client_secret"])
        json_asdict = json.loads(json_output)
        assert json_asdict.get("token") == creds.token
        assert json_asdict.get("refresh_token") == creds.refresh_token
        assert json_asdict.get("token_uri") == creds.token_uri
        assert json_asdict.get("client_id") == creds.client_id
        assert json_asdict.get("scopes") == creds.scopes
        assert json_asdict.get("client_secret") is None 
開發者ID:googleapis,項目名稱:google-auth-library-python,代碼行數:25,代碼來源:test_credentials.py

示例4: oauth2callback

# 需要導入模塊: from google.oauth2 import credentials [as 別名]
# 或者: from google.oauth2.credentials import client_secret [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 client_secret [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 client_secret [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 client_secret [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 client_secret [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 client_secret [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 client_secret [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_apply_with_no_quota_project_id

# 需要導入模塊: from google.oauth2 import credentials [as 別名]
# 或者: from google.oauth2.credentials import client_secret [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

示例12: test_with_quota_project

# 需要導入模塊: from google.oauth2 import credentials [as 別名]
# 或者: from google.oauth2.credentials import client_secret [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

示例13: test_credentials_with_scopes_requested_refresh_success

# 需要導入模塊: from google.oauth2 import credentials [as 別名]
# 或者: from google.oauth2.credentials import client_secret [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

示例14: test_credentials_with_scopes_returned_refresh_success

# 需要導入模塊: from google.oauth2 import credentials [as 別名]
# 或者: from google.oauth2.credentials import client_secret [as 別名]
def test_credentials_with_scopes_returned_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,
            "scopes": " ".join(scopes),
        }
        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,代碼行數:55,代碼來源:test_credentials.py

示例15: test_credentials_with_scopes_refresh_failure_raises_refresh_error

# 需要導入模塊: from google.oauth2 import credentials [as 別名]
# 或者: from google.oauth2.credentials import client_secret [as 別名]
def test_credentials_with_scopes_refresh_failure_raises_refresh_error(
        self, unused_utcnow, refresh_grant
    ):
        scopes = ["email", "profile"]
        scopes_returned = ["email"]
        token = "token"
        expiry = _helpers.utcnow() + datetime.timedelta(seconds=500)
        grant_response = {
            "id_token": mock.sentinel.id_token,
            "scopes": " ".join(scopes_returned),
        }
        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
        with pytest.raises(
            exceptions.RefreshError, match="Not all requested scopes were granted"
        ):
            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,代碼行數:59,代碼來源:test_credentials.py


注:本文中的google.oauth2.credentials.client_secret方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。