【发布时间】:2021-04-07 07:18:32
【问题描述】:
如何在 python 中为苹果登录和设备检查生成授权码/客户端密码?
【问题讨论】:
标签: python jwt apple-sign-in devicecheck
如何在 python 中为苹果登录和设备检查生成授权码/客户端密码?
【问题讨论】:
标签: python jwt apple-sign-in devicecheck
data = {
"iss": "team_id", # team id of your developer account this can be found in your apple developer portal => identifier of your app => "App ID prefix"
"iat": timestamp_now, # creation timestamp in seconds
"exp": timestamp_exp, # expiration timestamp in seconds (max 20 mins) see
"aud": "https://appleid.apple.com",
"sub": client_id # your bundle
}
with open("filename.p8", "r") as f:
private_key = f.read()
token = jwt.encode(payload=data, key=private_key, algorithm="ES256", headers={
"kid":key_id # the key id is the id u saved in step 1
}).decode()
完整的代码如下所示
import jwt
def generate_token()
with open("filename.p8", "r") as f:
private_key = f.read()
team_id = "teamid"
client_id = "bundle.id"
key_id = "keyid"
validity_minutes = 20
timestamp_now = int(utils.time_stamp_seconds())
timestamp_exp = timestamp_now + (60 * validity_minutes)
cls.last_token_expiration = timestamp_exp
data = {
"iss": team_id,
"iat": timestamp_now,
"exp": timestamp_exp,
"aud": "https://appleid.apple.com",
"sub": client_id
}
token = jwt.encode(payload=data, key=private_key, algorithm="ES256", headers={"kid": key_id}).decode()
【讨论】: