fyangq

from itsdangerous import JSONWebSignatureSerializer
import jwt

def generate_jwt(secret,payload):
headers={
"alg": "HS256",
"typ": "JWT"
}

s=JSONWebSignatureSerializer(secret)
s=s.dumps(payload,header_fields=headers)
return s


def decode_jwt(secret,jwt_token):

try:
data=jwt.decode(jwt_token,secret,algorithms=[\'HS256\'])
return data
except Exception as e:
raise e



if __name__ == \'__main__\':

secret= "xxxxxx"
payload={
"iss": "xxx",
"exp": 1669229208,
"userId": "xxxx"
}


jwt_token=generate_jwt(secret,payload)
print(decode_jwt(secret,jwt_token))


分类:

技术点:

相关文章:

  • 2021-07-23
  • 2022-12-23
  • 2022-01-07
  • 2022-12-23
  • 2022-12-23
  • 2021-09-29
  • 2021-09-17
  • 2022-12-23
猜你喜欢
  • 2021-11-30
  • 2022-01-07
  • 2021-09-06
  • 2022-01-07
  • 2022-01-07
  • 2021-11-03
  • 2022-12-23
相关资源
相似解决方案