RESTful service with access control

91 views
Skip to first unread message

Jim S

unread,
May 13, 2019, 12:28:11 PM5/13/19
to web2py-users
Hi

I'm setting up a REST service that requires authentication.  I'm following the example here:


Here is the example with basic login:

auth.settings.allow_basic_login = True

@auth.requires_login()
@request.restful()
def api():
   
def GET(s):
       
return 'access granted, you said %s' % s
return locals()

However, I'd like to use email authentication instead of basic_login.  

When I remove the first line, and pass proper email address and password, I get a 403 return code.

Anyone had success with a RESTful service using email authentication?

-Jim

Val K

unread,
May 13, 2019, 12:51:27 PM5/13/19
to web2py-users
As far as I understand, basic means passing login and password in the headers and it doesn't matter if username or email is used as login, no?

Jim S

unread,
May 13, 2019, 1:39:27 PM5/13/19
to web2py-users
Shoot, looks like my initial testing wasn't even working.  I was just checking the status code which was returning 200, but didn't realize it was redirecting me to the login page.  Any way i can stop that?

-Jim

Val K

unread,
May 13, 2019, 2:20:30 PM5/13/19
to web2py-users
For services I use auth.login_bare(u,p) and handmade decorator based on auth.is_logged_in() - don't forget about parens!

Val K

unread,
May 13, 2019, 2:34:41 PM5/13/19
to web2py-users

Jim Steil

unread,
May 13, 2019, 9:38:51 PM5/13/19
to web...@googlegroups.com
Val

Thanks so much for the references.  However, I'm really a bit lost.

Using login_bare()??  Where does that come in to play?  And then a custom decorator?

Am I doing something wrong that is preventing the sample in the book from working?  Not sure why mine is just redirecting.

Any samples would really be appreciated.

-Jim


On Mon, May 13, 2019 at 1:34 PM Val K <valq...@gmail.com> wrote:
There is also https://github.com/web2py/web2py/blob/master/gluon/authapi.py

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/7DfbZY6xRWU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/913ce0a6-a2fa-4529-b934-dc2e3de1d1c0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jim Steil

unread,
May 13, 2019, 10:17:38 PM5/13/19
to web...@googlegroups.com
Val

I just created a test app based on the code in the book and all is working as it should.  Must be something else in my other app that is causing the trouble.

I'll check it out later.  Also looking into JWT...

Val K

unread,
May 14, 2019, 1:10:11 AM5/14/19
to web2py-users
One yet important moment:
Do you set the view for your api?
I mean, that book example will not work without response.view='generic.json' if request is not local.

Massimo Di Pierro

unread,
May 14, 2019, 2:51:24 AM5/14/19
to web2py-users
You may want to see my other post about the new policy based DBAPI.

Jim Steil

unread,
May 14, 2019, 8:20:57 AM5/14/19
to web...@googlegroups.com
Massimo - thanks for that info.  This won't help in my case as I'm using the RESTful API to get access to another of my server-side python packages.  But, I can see the power of the DBAPI.  I'm waiting for you to stabilize web3py before I jump in.  I'd love to get involved in more testing but I haven't been able to free up the time. 

My current python2 web2py app is too big for me to try to bring to web3py before the Python 2 drop dead date so I'm also working to test all of that under python 3. It's a busy (and exciting) year!

Thanks again for all  you do!

-Jim

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/7DfbZY6xRWU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.

Jim S

unread,
May 14, 2019, 10:19:10 AM5/14/19
to web2py-users
Yes, I have the view set.   

I have it working now if I use the password stored in my auth_user table.  But, I'd really prefer to have it go through all available authentication methods to authenticate a user.  We have some users that authenticate to our mail server and others that use the password in auth_user.  It's not a show-stopper, using the auth_user password will work for me.

Thanks for sticking with me on this one.

-Jim
Reply all
Reply to author
Forward
0 new messages