How to use the aiogoogle.models.Request function in aiogoogle

To help you get started, we’ve selected a few aiogoogle examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github omarryhan / aiogoogle / tests / test_units / test_auth / test_api_key.py View on Github external
def test_adds_key_to_url_without_query(manager, key1):
    url = "https://example.com/api"
    req = Request(url=url)
    request_with_key = manager.authorize(req, key1)
    assert request_with_key.url == url + "?key=" + key1
github omarryhan / aiogoogle / tests / test_units / test_client / test_request.py View on Github external
def test_request_constructor():
    req = Request(
        method='GET',
        url='https://example.com/api/v1/example_resource?example_query=example_arg',
        headers={'Authorization': 'Bearer asdasdasd'},
        json={'data': 'asasdasd'},
        media_upload=MediaUpload('asdasd'),
        media_download=MediaDownload('assda')
    )
github omarryhan / aiogoogle / tests / test_units / test_auth / test_oauth2.py View on Github external
def test_authorize(manager):
    access_name = "access"
    unauth_req = Request()
    user_creds = {"access_token": access_name}

    auth_req = manager.authorize(unauth_req, user_creds)
    assert auth_req.headers["Authorization"] == "Bearer " + access_name

    with pytest.raises(KeyError):
        auth_req = manager.authorize(unauth_req, {})
github omarryhan / aiogoogle / tests / test_units / test_auth / test_api_key.py View on Github external
def test_adds_key_to_url_without_query_and_with_slash(manager, key1):
    url = "https://example.com/api/"
    req = Request(url=url)
    request_with_key = manager.authorize(req, key1)
    assert request_with_key.url == url[:-1] + "?key=" + key1
github omarryhan / aiogoogle / aiogoogle / auth / managers.py View on Github external
def _build_revoke_request(self, user_creds):
        return Request(
            method="POST",
            headers={"content-type": URLENCODED_CONTENT_TYPE},
            url=self["revocation_endpoint"],
            data=dict(token=user_creds["access_token"]),
        )
github omarryhan / aiogoogle / aiogoogle / auth / managers.py View on Github external
async def _get_openid_certs(self):
        request = Request(
            method="GET",
            url=GOOGLE_OAUTH2_CERTS_URL,
            # url=self['jwks_uri'],  # which is: https://www.googleapis.com/oauth2/v3/certs isn't compatible with google.auth. Falling back to v1
        )
        return await self._send_request(request)
github omarryhan / aiogoogle / aiogoogle / auth / managers.py View on Github external
async def _refresh_openid_configs(self):
        """
        Downloads fresh openid discovery document and sets it to the current manager.

        OpenID configs are used for both OAuth2 manager and OpenID connect manager.

        Unless this test is failing:

        aiogoogle.tests.integ_online.latest_test_latest_openid_configs(), You shouldn't really need to use this. 
        """
        req = Request("GET", url=OPENID_CONFIGS_DISCOVERY_DOC_URL)
        self.openid_configs = await self._send_request(req)
github omarryhan / aiogoogle / aiogoogle / auth / managers.py View on Github external
def _build_user_creds_req(self, grant, client_creds, grant_type) -> Request:
        data = dict(
            code=grant,
            client_id=client_creds["client_id"],
            client_secret=client_creds["client_secret"],
            redirect_uri=client_creds["redirect_uri"],
            grant_type=grant_type,
        )
        headers = {"content-type": URLENCODED_CONTENT_TYPE}
        method = "POST"
        url = self["token_endpoint"]
        return Request(method, url, headers, data=data)
github omarryhan / aiogoogle / aiogoogle / auth / managers.py View on Github external
def _build_refresh_request(self, user_creds, client_creds):
        data = dict(
            grant_type=REFRESH_GRANT_TYPE,
            client_id=client_creds["client_id"],
            client_secret=(client_creds["client_secret"]),
            refresh_token=(user_creds["refresh_token"]),
        )
        method = "POST"
        headers = {"content-type": URLENCODED_CONTENT_TYPE}
        return Request(method, self["token_endpoint"], headers, data=data)
github omarryhan / aiogoogle / aiogoogle / method.py View on Github external
# Process download_file
        if download_file:
            if validate is True:
                if getattr(self, 'supportsMediaDownload', None) is not True:
                    raise ValidationError('download_file was provided while method doesn\'t support media download')
            media_download = MediaDownload(download_file)
        else:
            media_download = None

        # Process upload_file
        if upload_file:
            media_upload = self._build_upload_media(upload_file)
        else:
            media_upload = None

        return Request(
            method=self.httpMethod,
            url=uri,
            data=data,
            json=json,
            timeout=timeout,
            media_download=media_download,
            media_upload=media_upload
        )