Hello Massimo,
Since web2py is very slow (according to a benchmark I've seen), and py4web is much faster, I'm interested in moving to py4web but I'm not sure how to handle the transition.
My web2py app is used as a service layer communicating with the JavaScript frontend via json-rpc.
It uses web2py JWT tokens for auth (sent as Authorization: Bearer <token> header).
How can I handle the same architecture in py4web?
I think the same question should be valid for REST services requiring authentication.
Basically, something like this:
myjwt = AuthJWT(auth, secret_key='SecretKey', expiration=3000000)
@cors_allow
@catch303
@myjwt.allows_jwt()
@auth.requires_login()
def call():
session.forget()
return service()
@service.jsonrpc2
def create(lesson_id, question, answer, reading, context, weight, examples):
card_id = db.card.insert(
lesson_id=lesson_id,
user_id=auth.user.id,
question=question,
answer=answer,
reading=reading,
context=context,
weight=weight,
examples=examples
)
return int(card_id)
How can I get the token, refresh the token, revoke it, how can I use it to authenticate json-rpc requests (or REST requests for that matter)?
{appname}/auth/api/register (POST)
{appname}/auth/api/login (POST)
{appname}/auth/api/request_reset_password (POST)
{appname}/auth/api/reset_password (POST)
{appname}/auth/api/verify_email (GET, POST)
{appname}/auth/api/logout (GET, POST) (+)
{appname}/auth/api/profile (GET, POST) (+)
{appname}/auth/api/change_password (POST) (+)
{appname}/auth/api/change_email (POST) (+)
You auth api are best explained with the examples in the tests https://github.com/web2py/py4web/blob/master/tests/test_auth.py You would only use the API to login if you want to get a session cookie and authenticate using that. There is no api to use the username:password to obtain an authentication token. Is it assumed a user logins and uses that UI to get the token. Are you trying to automate this step? Don't you want a human to manually register and obtain the token? What is the desired workflow?
--
You received this message because you are subscribed to the Google Groups "py4web" group.
To unsubscribe from this group and stop receiving emails from it, send an email to py4web+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/py4web/5b049afc-bb54-4a6e-b36b-a76dc6d29863n%40googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/py4web/f43117c5-03fc-49a1-bc19-ead41d4ad517n%40googlegroups.com.
I will try to rethink the whole approach to authentication in my app.The question remains: does the proposed tokens API expose methods for programmatically managing (creating, expiring, deleting) tokens (as opposed to using a Grid UI)?