我是这样设置的..
使用库。 下面 -- 您需要将这些属性从 Identity Provider (IdP) 传递到 数据库。您的json config 通过xs-security 将允许权限范围。
-
首先下载 Python:sap_xsseclib. 它应该允许您获取 JWT 令牌的属性。
-
其次,设置你的服务和安全
//import these lib. after downloading
from sap import xssec
from cfenv import AppEnv
// get your env.
myEnv = AppEnv()
// get your UAA service
myService = myEnv.get_service(name='<uaa_service_name>').credentials
// now your JWT access token for
contextWithAccessToken = xssec.create_security_context(access_token, myService)
接下来配置你的xs-security文件
Example xs-security.json File
{
"xsappname" : "node-hello-world",
"scopes" : [ {
"name" : "$XSAPPNAME.Display",
"description" : "display" },
{
"name" : "$XSAPPNAME.Edit",
"description" : "edit" },
{
"name" : "$XSAPPNAME.Delete",
"description" : "delete" }
],
"attributes" : [ {
"name" : "Country",
"description" : "Country",
"valueType" : "string" },
{
"name" : "CostCenter",
"description" : "CostCenter",
"valueType" : "int" }
],
"role-templates": [ {
"name" : "Viewer",
"description" : "View all books",
"scope-references" : [
"$XSAPPNAME.Display" ],
"attribute-references": [ "Country" ]
},
{
"name" : "Editor",
"description" : "Edit, delete books",
"scope-references" : [
"$XSAPPNAME.Edit",
"$XSAPPNAME.Delete" ],
"attribute-references" : [
"Country",
"CostCenter"]
}
]
}
// 为您的环境准备好用户值。 XS_APPLICATIONUSER 或 $env.user.value
-
设置你的@sap/hana-client 调用
用connection.session.XS_APPLICATIONUSER = <JWT TOKEN>;
-
不要忘记设置 sap-jwt/py-jwt 库以验证 jwt 令牌
刚刚设置
USE_SAP_PY_JWT = true
你已经完成了!