So, this is how I use it now, while rdegges should not create this function in flask-stormpath.
You will need the latest python sdk to storm and upgrade it with func tools.
from stormpath.api_auth import (PasswordGrantAuthenticator, RefreshGrantAuthenticator, JwtAuthenticator)
from functools import wraps
You can create your application as such.
stormpathClient = Client(id=KEYS['STORMPATH_ID'], secret=KEYS['STORMPATH_SECRET'])
stormpathApp = stormpathClient.applications.search('your-application')[0]
This decorator will help you with fixing the end points.
def tokenRequired(func):
"""
Decorator to apply on all routes which require tokens.
"""
@wraps(func)
def wrappingFunc():
authHeader = request.headers.get('Authentication')
if len(authHeader)<8 or (not authHeader[:7] == 'Bearer ') or (
not authHeader):
return Response("401 Unauthorized",401)
authToken = authHeader[7:]
try:
authenticator = JwtAuthenticator(stormpathApp)
authResult = authenticator.authenticate(authToken)
request.vUser = authResult.account
except:
return Response("403 Forbidden",403)
return func()
return wrappingFunc
@flaskApp.route('/secure-route',methods=['GET','POST'])
@tokenRequired
def secureEndpoint():
return Response("This is secure Mr." + request.vUser.given_name ,200)
Let me know in the comments if anyone wants to know a marker that gives out and refresh endpoints.
Vasif source
share