Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
mxrch
GitHub Repository: mxrch/GHunt
Path: blob/master/ghunt/apis/identitytoolkit.py
252 views
1
from ghunt.objects.base import GHuntCreds
2
from ghunt.errors import *
3
import ghunt.globals as gb
4
from ghunt.objects.apis import GAPI, EndpointConfig
5
from ghunt.parsers.identitytoolkit import ITKProjectConfig
6
7
import httpx
8
9
from typing import *
10
import inspect
11
import json
12
13
14
class IdentityToolkitHttp(GAPI):
15
def __init__(self, creds: GHuntCreds, headers: Dict[str, str] = {}):
16
super().__init__()
17
18
if not headers:
19
headers = gb.config.headers
20
21
base_headers = {}
22
23
headers = {**headers, **base_headers}
24
25
self.hostname = "www.googleapis.com"
26
self.scheme = "https"
27
28
self._load_api(creds, headers)
29
30
async def get_project_config(self, as_client: httpx.AsyncClient, api_key: str) -> Tuple[bool, ITKProjectConfig]:
31
endpoint = EndpointConfig(
32
name = inspect.currentframe().f_code.co_name,
33
verb = "GET",
34
data_type = None, # json, data or None
35
authentication_mode = None, # sapisidhash, cookies_only, oauth or None
36
require_key = None, # key name, or None
37
)
38
self._load_endpoint(endpoint)
39
40
base_url = "/identitytoolkit/v3/relyingparty/getProjectConfig"
41
42
params = {
43
"key": api_key
44
}
45
46
req = await self._query(endpoint.name, as_client, base_url, params=params)
47
48
# Parsing
49
data = json.loads(req.text)
50
51
project_config = ITKProjectConfig()
52
if "error" in data:
53
return False, project_config
54
55
project_config._scrape(data)
56
57
return True, project_config
58