如何在python中生成JWT断言

2024-03-28 18:38:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试实现SalesforceEinstein,并尝试为他们的api获得授权

docs中写着:

Create the JWT payload. The payload is JSON that contains:

sub—Your email address. This is your email address contained in the Salesforce org you used to sign up for an Einstein Platform Services account.

aud—The API endpoint URL for generating a token.

exp—The expiration time in Unix time. This value is the current Unix time in seconds plus the number of seconds you want the token to be valid. For testing purposes, you can get the Unix time at Time.is.

The JWT payload looks like this JSON.

JSON

{
  "sub": "<EMAIL_ADDRESS>",
  "aud": "https://api.einstein.ai/v2/oauth2/token",
  "exp": <EXPIRATION_SECONDS_IN_UNIX_TIME>
}

Sign the JWT payload with your RSA private key to generate an assertion. The private key is contained in the einstein_platform.pem file you downloaded when you signed up for an account. The code to generate the assertion varies depending on your programming language. If you're doing manual testing, you can generate an assertion using jwt.io.

如何在python中生成断言字符串?在

发现jwt处理可以用pyjwt完成。 https://pyjwt.readthedocs.io/en/latest/ 但是我搞不清到底要做什么才能得到断言字符串。在

调用curl请求以获得响应

^{pr2}$

但得到的答案是

{
    "message": "Invalid JWT assertion"
}

Tags: thetointokenyouanjsonfor