通过API或SDK启用Firebase身份验证
作为我项目的一部分,我需要从API或SDK启用firebase身份验证。 我没有找到任何解决方案-唯一的方法是从控制台启用它 有人熟悉吗 编辑:我终于找到了启用GCP服务的解决方案。通过API或SDK启用Firebase身份验证,api,firebase-authentication,Api,Firebase Authentication,作为我项目的一部分,我需要从API或SDK启用firebase身份验证。 我没有找到任何解决方案-唯一的方法是从控制台启用它 有人熟悉吗 编辑:我终于找到了启用GCP服务的解决方案。 下面的链接解释了如何通过REST启用GCP服务:经过长时间的搜索,我找到了方法: serviceusage Google API提供了一个REST API,用于启用/禁用GCP服务。请注意,启用服务后,需要启用signIn方法。您可以在下面的代码中看到示例 服务启用: url = 'https://servi
下面的链接解释了如何通过REST启用GCP服务:经过长时间的搜索,我找到了方法: serviceusage Google API提供了一个REST API,用于启用/禁用GCP服务。请注意,启用服务后,需要启用signIn方法。您可以在下面的代码中看到示例 服务启用:
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)
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)
启用登录方法:
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)
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)
请注意:访问令牌是从服务帐户JSON文件生成的:
credentials = service_account.Credentials.from_service_account_file(
<YOUR_JSON_SERVICE_ACCOUNT_PATH>, scopes=CREDENTIAL_SCOPES)
credentials.refresh(requests.Request())
return credentials.token
credentials=service\u account.credentials.from\u service\u account\u文件(
,作用域=凭证(作用域)
credentials.refresh(requests.Request())
返回凭据.token
您的确切问题是什么?这里不是论坛。请明确地问您的问题,并具体说明。要启用提供程序,这是我能想到的最好方法:我需要以编程方式启用身份验证方法。-我从firebase用户界面添加了一张图片。因此,我需要从API或SDK中启用它,而不是从UI中按“开始”按钮。@FrankvanPuffelen-谢谢,但我需要启用signIn方法,所以这似乎不是我的方式。