def test_refresh(authorized_user_file, http_request, token_info): with open(authorized_user_file, "r") as fh: info = json.load(fh) credentials = google.oauth2.credentials.Credentials( None, # No access token, must be refreshed. refresh_token=info["refresh_token"], token_uri=GOOGLE_OAUTH2_TOKEN_ENDPOINT, client_id=info["client_id"], client_secret=info["client_secret"], ) credentials.refresh(http_request) assert credentials.token info = token_info(credentials.token) info_scopes = _helpers.string_to_scopes(info["scope"]) # Canonical list of scopes at https://cloud.google.com/sdk/gcloud/reference/auth/application-default/login # or do `gcloud auth application-defaut login --help` assert set(info_scopes) == set([ "https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/cloud-platform", "openid", ])
def test_refresh(http_request, token_info): credentials = compute_engine.Credentials() credentials.refresh(http_request) assert credentials.token is not None assert credentials.service_account_email is not None info = token_info(credentials.token) info_scopes = _helpers.string_to_scopes(info["scope"]) assert set(info_scopes) == set(credentials.scopes)
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)
async def test_refresh_success(http_request, credentials, token_info): credentials = credentials.with_scopes(["email", "profile"]) await credentials.refresh(http_request) assert credentials.token info = await token_info(credentials.token) assert info["email"] == credentials.service_account_email info_scopes = _helpers.string_to_scopes(info["scope"]) assert set(info_scopes) == set([ "https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/userinfo.profile", ])
def _retrieve_info(self, request): """Retrieve information about the service account. Updates the scopes and retrieves the full service account email. Args: request (google.auth.transport.Request): The object used to make HTTP requests. """ info = _metadata.get_service_account_info( request, service_account=self._service_account_email) self._service_account_email = info['email'] self._scopes = _helpers.string_to_scopes(info['scopes'])
def test_refresh_success(http_request, credentials, token_info): credentials = credentials.with_scopes(['email', 'profile']) credentials.refresh(http_request) assert credentials.token info = token_info(credentials.token) assert info['email'] == credentials.service_account_email info_scopes = _helpers.string_to_scopes(info['scope']) assert set(info_scopes) == set([ 'https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile' ])
def test_refresh(authorized_user_file, http_request, token_info): with open(authorized_user_file, 'r') as fh: info = json.load(fh) credentials = google.oauth2.credentials.Credentials( None, # No access token, must be refreshed. refresh_token=info['refresh_token'], token_uri=GOOGLE_OAUTH2_TOKEN_ENDPOINT, client_id=info['client_id'], client_secret=info['client_secret']) credentials.refresh(http_request) assert credentials.token info = token_info(credentials.token) info_scopes = _helpers.string_to_scopes(info['scope']) assert set(info_scopes) == set([ 'https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile' ])