-
Notifications
You must be signed in to change notification settings - Fork 1
/
deserialize_the_token.py
executable file
·35 lines (26 loc) · 1.19 KB
/
deserialize_the_token.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
#!/usr/bin/env python
from create_the_token import get_macaroon
submitted_token = get_macaroon()
def deserialize(token=submitted_token):
import macaroons
return macaroons.deserialize(token)
def deserialize_verbose(token=submitted_token):
# START 1 OMIT
import macaroons
# token = "MDAyNmxvY2F0aW9uIGh0dHA6Ly93d3cucHl0aG9uLm9yLmlkLwowMDIzaWRlbnRpZmllciBrb3BkYXJfbWVtYmVyc19vbmx5CjAwMmZzaWduYXR1cmUgPTBa1YP4kNcWeZ9bEeBLautN8R9XueRXQ5uHZ4eQFxAK"
# first, we attempt to rehydrate a valid macaroon instance from the string # // HL
try:
print('Token to be deserialized: %s' % token)
submitted_macaroon = macaroons.deserialize(token) # // HL
# we can check its details
print('submitted_macaroon.inspect():')
print(submitted_macaroon.inspect())
except macaroons.MacaroonError:
print('The token provided is not a valid macaroon: %s' % token)
except:
print 'An unknown error occurred while deserializing the token'
# END 1 OMIT
if __name__ == "__main__":
# request the token for inspection
#submitted_token = raw_input('Enter token to be inspected: ') or submitted_token
deserialize_verbose(submitted_token)