forked from Trustie-Study-Group/PRWelBot4SECourse
47 lines
1.2 KiB
Python
47 lines
1.2 KiB
Python
#!/usr/bin/python
|
|
# 负责调用平台接口 完成各项操作
|
|
import json
|
|
import sys
|
|
sys.path.append('..')
|
|
import jwt
|
|
import time
|
|
import sys
|
|
|
|
|
|
# 通过bot基本信息字段获取JWT 和 token
|
|
def getJWT():
|
|
if len(sys.argv) > 1:
|
|
pem = sys.argv[1]
|
|
else:
|
|
# pem = input("Enter path of private PEM file: ")
|
|
pem = 'C:\\Users\\文学奖\\Downloads\\my-first-apps1.2023-02-05.private-key (1).pem' # (1)
|
|
|
|
# Get the App ID
|
|
if len(sys.argv) > 2:
|
|
app_id = sys.argv[2]
|
|
else:
|
|
# app_id = input("Enter your APP ID: ")
|
|
app_id = 10009 #"CrnV5uYEmwMGu7H6osHHi-4aSyKdY99qRMw4i44Kfi4" #186702
|
|
|
|
# Open PEM
|
|
with open(pem, 'rb') as pem_file:
|
|
signing_key = jwt.jwk_from_pem(pem_file.read())
|
|
#signing_key = jwt.jwk_from_pem(privateKey)
|
|
|
|
payload = {
|
|
# Issued at time
|
|
'iat': int(time.time()),
|
|
# JWT expiration time (10 minutes maximum)
|
|
'exp': int(time.time()) + 600,
|
|
# GitHub App's identifier
|
|
'iss': app_id
|
|
}
|
|
|
|
# Create JWT
|
|
jwt_instance = jwt.JWT()
|
|
encoded_jwt = jwt_instance.encode(payload, signing_key, alg='RS256')
|
|
print(f"JWT: ", encoded_jwt)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
print("hello") |