NetSuite python TBA 身份验证 [英] NetSuite python TBA Authentication
问题描述
我对使用 SOAP 进行 NetSuite 调用这一领域不熟悉.因此,我可能完全错误地思考如何解决问题.这是我试图解决的问题:- 语言:Python+ Zeep- 我想将我的应用程序从电子邮件传递移动到基于令牌的身份验证.
I am new to this area of using SOAP for NetSuite calls. Hence, I might be thinking completely incorrectly on how to solve the problem. Here is what I am trying to solve: - Language: Python+ Zeep - I want to move my application from email pass to Token based authentication.
在 Python 中,我能够为 TokenPassport 生成所有参数.这是我感到困惑的地方:我在堆栈上查找了一些代码,并注意到人们正在使用 client.service.login() 方法登录.此方法采用通行证而不是令牌通行证对象.是否有单独的方法可以使用 tokenpassport obj 进行登录?,或者我是否需要生成(硬编码)带有参数的 XML,并将其作为数据传入标头?
In Python I am able to generate all the parameters for TokenPassport. Here is where I am confused: I looked up some code on stack and noticed that folks were using client.service.login() method to login. This method takes the passport and not the tokenpassport obj. Is there a separate method that takes tokenpassport obj for login?, Or do I need to generate(hardcode) an XML with the parameters and is this passed in header as data?
谢谢
推荐答案
希望下面的代码对刚开始的人有所帮助.
Hope the below code helps someone who is starting out.
base = '&'.join([nsAccountID, consumerKey, token, Nonce, currentTime])
key = '&'.join([consumerSecret, tokenSecret])
digest = hmac.new(str.encode(key), msg=str.encode(base), digestmod=hashlib.sha256).digest()
signature = base64.b64encode(digest).decode()
tokenPassport = client.get_type('ns0:TokenPassport')
PassportSignature = client.get_type('ns0:TokenPassportSignature')
tokenPassportSignature = PassportSignature(signature, "HMAC-SHA256" )
clientPass = tokenPassport(account=nsAccountId, consumerKey = consumerKey, token= token, nonce= Nonce, timestamp=currentTime, signature=tokenPassportSignature)
search = client.get_type('ns5:ItemSearchBasic')
searchCriteriaComplex = client.get_type('ns0:SearchStringField')
searchCriteria = searchCriteriaComplex(searchValue= "Test Display Name - tax", operator="is")
searchItem = search(displayName = searchCriteria)
testRes = client.service.search(searchRecord= searchItem, _soapheaders={"tokenPassport": clientPass})
这篇关于NetSuite python TBA 身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!