Permalink
Browse files

Minimal JWT implementation

  • Loading branch information...
1 parent d60171b commit 987955b9bafbb9ed670694a05f31b330e0f75683 @brianloveswords committed Jun 2, 2011
Showing with 15 additions and 0 deletions.
  1. +15 −0 examples/minijwt.py
View
15 examples/minijwt.py
@@ -0,0 +1,15 @@
+import jws
+def to_jwt(claim, algo, key):
+ header = {'typ': 'JWT', 'alg': algo}
+ return "%s.%s.%s" % [
+ jws.utils.encode(header),
+ jws.utils.encode(claim),
+ jws.sign(header, claim, key)
+ ]
+def from_jwt(jwt, key):
+ (header, claim, sig) = jwt.split('.')
+ header = jws.utils.decode(header)
+ claim = jws.utils.decode(claim)
+ jws.verify(header, claim, sig, key)
+ return claim
+

0 comments on commit 987955b

Please sign in to comment.