Skip to content

Commit

Permalink
Merge pull request #2 from zlorb/master
Browse files Browse the repository at this point in the history
Allow for custom Authorization header

Thanks!
  • Loading branch information
tgs committed Jul 21, 2015
2 parents b634669 + 2f1b923 commit a212875
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions requests_jwt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ class JWTAuth(AuthBase):
See the documentation of :mod:`PyJWT` for the list of available
algorithms.
"""
def __init__(self, secret, alg='HS256'):
def __init__(self, secret, alg='HS256', authorization_header='JWT token="%s"'):
self.secret = secret
self.alg = alg
self._authHeader = authorization_header
self._generators = {}

def add_field(self, name, generator):
Expand Down Expand Up @@ -125,6 +126,12 @@ def expire(self, secs):
self.add_field('exp',
lambda req: int(time.time() + secs))

def set_header(self, authorization_header='JWT token="%s"'):
"""
Modify authorization header from default 'JWT token="%s"'.
"""
self._authHeader = authorization_header

def _generate(self, request):
"""
Generate a payload for the given request.
Expand Down Expand Up @@ -154,5 +161,5 @@ def __call__(self, request):
#import pdb; pdb.set_trace()
token = jwt.encode(payload, self.secret, self.alg)

request.headers['Authorization'] = 'JWT token="%s"' % token.decode('ascii')
request.headers['Authorization'] = self._authHeader % token.decode('ascii')
return request

0 comments on commit a212875

Please sign in to comment.