首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Python从Auth0获取用户列表和总计

问如何使用Python从Auth0获取用户列表和总计
EN

Stack Overflow用户
提问于 2021-11-01 12:24:47
回答 1查看 100关注 0票数 0

如何使用Python语言从Auth0帐户获取所有用户的列表并获取总数?

EN

回答 1

Stack Overflow用户

发布于 2021-11-01 12:24:47

Auth0允许使用API token获取数据。要获取包括总数在内的用户详细信息,您需要API客户端密码和id。

Auth0 document to get the token

我写了一篇文章here

要使用的代码...

代码语言:javascript
复制
import http.client
import json

client_id = 'xxxxxxxxxxxxxxxxxxxx'
client_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
business_name = 'xxxxxxxxx'

# GET THE ACCESS TOKEN using the client_id and client_secret
conn = http.client.HTTPSConnection(business_name+".eu.auth0.com")
payload = "{\"client_id\":\""+client_id+"\",\"client_secret\":\""+client_secret+"\",\"audience\":\"https://"+business_name+".eu.auth0.com/api/v2/\",\"grant_type\":\"client_credentials\"}"
headers = { 'content-type': "application/json" }
conn.request("POST", "/oauth/token", payload, headers)
res = conn.getresponse()
data = res.read()
tokendetails_json = data.decode('utf8').replace("'", '"')
# Load the JSON to a Python list & dump it back out as formatted JSON
tokendetails = json.loads(tokendetails_json)


#NOW GET THE USERS AND TOTAL
conn = http.client.HTTPSConnection(business_name+".eu.auth0.com")
payload = "{\"client_id\":\""+client_id+"\",\"client_secret\":\""+client_secret+"\",\"audience\":\"https://"+business_name+".eu.auth0.com/api/v2/\",\"grant_type\":\"client_credentials\"}"
headers = { 'content-type': "application/json","Authorization": "Bearer "+tokendetails['access_token'] }
conn.request("GET", "/api/v2/users?include_totals=true", payload, headers)
res = conn.getresponse()
data = res.read()
result_data_json = data.decode('utf8').replace("'", '"')

# Load the JSON to a Python list & dump it back out as formatted JSON
result_data = json.loads(result_data_json)
print(result_data)                  # Json list of all users
print(result_data['total'])         # Just the count of total users
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69796896

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档