-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
41 lines (34 loc) · 949 Bytes
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# -*- coding: utf-8 -*-\
import json, time, chardet
from jwt.api_jwt import wdJwt
from jwt.utils import base64urlencode, force_unicode
if __name__ == "__main__":
wd = wdJwt()
start_time = int(time.time())
print 'header: ', wd.generate_header()
payload_str = force_unicode(json.dumps({
'nickname' : u'王强',
'gender': 1
}))
print 'payload: ', wd.generate_payload(payload_str)
print 'signature: ', wd.generate_signature()
first_token = wd.generate_token()
print 'token: ', first_token
print 'token code: ', chardet.detect(first_token)
print 'verify token', wd.verify_token(first_token)
# FormatError
try:
wd.verify_token(first_token+".d")
except Exception, e:
print "verify token ", e
# LosedError
try:
wd.verify_token(first_token+"s")
except Exception, e:
print "verify token", e
# TimeoutTokenError
time.sleep(7)
try:
wd.verify_token(first_token)
except Exception, e:
print "verify token", e