After my long search I found the way:
The serviceusage Google API provides a REST API for enabling/disabling GCP service. PLease note that after the service enabled, it needed to enable the signIn method. You can see examples from my code below.
Service Enabling:
url =
'https://serviceusage.googleapis.com/v1/projects/{IDENTIFIER:}/services:batchEnable'.format(IDENTIFIER=project_idetifier)
if verbose: print(bcolors.INFO + 'GET URL: {url:}'.format(url=url) + bcolors.ENDC)
headers={'Authorization': 'Bearer {token:}'.format(token=access_token),\
'Accept': 'application/json', 'Content-Type': 'application/json'}
payload = {
"serviceIds": ["identitytoolkit"],
}
r = httpReq.post(url, data=json.dumps(payload), headers=headers)
resp_body = json.loads(r.text)
Enable SignIn Method:
url = 'https://identitytoolkit.googleapis.com/admin/v2/projects/{project_id:}/config?updateMask=signIn.email.enabled,signIn.email.passwordRequired'.format(project_id=project_id)
headers={'Authorization': 'Bearer {token:}'.format(token=access_token),\
'Accept': 'application/json', 'Content-Type': 'application/json'}
payload = {"signIn": {"email": {"enabled": True, "passwordRequired": True}}}
r = httpReq.patch(url, data=json.dumps(payload), headers=headers)
resp_body = json.loads(r.text)
Just a note: The access token was generated from the service account JSON file:
credentials = service_account.Credentials.from_service_account_file(
<YOUR_JSON_SERVICE_ACCOUNT_PATH>, scopes=CREDENTIAL_SCOPES)
credentials.refresh(requests.Request())
return credentials.token