我正在尝试使用 Python 通过 Admin REST API 创建 Keycloak 客户端。
我尝试了以下方法:
进口请求
导入参数解析
进口AST
def get_token():
url = 'http://localhost:9003/auth/realms/master/protocol/openid-connect/token'
参数 = {
'client_id': 'admin-cli',
'grant_type': '密码',
'用户名':'管理员',
'密码':'密码'
}
return ast.literal_eval(requests.post(url, params, verify=False).content.decode("utf-8"))['access_token']
#return requests.post(url, params, verify=False).content.decode('utf-8')
def create_client():
url ='http://localhost:9003/auth/admin/realms/master/clients'
标题 = {
'内容类型':'应用程序/json',
'授权':'承载'+ str(get_token)
}
参数 = {
"clientId":"testclient-3",
#"id":"3",
#"name": "testclient-3",
#"description": "TESTCLIENT-3",
#"启用": 真,
#"redirectUris":[ "\\" ],
#"publicClient": 真
}
返回 requests.post(url, headers, params, verify=False)
x = create_client()
打印 (x)
我收到了 401 HTTP 代码,任何人都可以帮我解决这个问题吗?
先感谢您。
PS:9003 …