web2py AWS cognito authentication

105 views
Skip to first unread message

kryto...@gmail.com

unread,
Sep 18, 2018, 9:09:06 AM9/18/18
to web2py-users

I am changing the login authentication to be handled by AWS Cognito and require some clarification around the approach as cannot get it to work correctly

  1. I have created a class cog_login that has been assigned to the

auth.settings.login_methods = [cog_login]

  1. One of the functions that is in the class is called authenticate() that takes username and password arguments that the user enters from the standard web2py forms user/login

  2. In the def user() controller in default I have the following:

cog_login().authenticate(request.vars.email, request.vars.password)

This queries AWS and returns True if passes, False otherwise.

  1. I am not clear on what to do with the True, False response within the def user() as it doesn't seem to populate auth.user which always remains as None.

  2. I have tried to force the population of auth.user getting the contents of auth_user, i.e. auth.user = row[0]. This does populate auth.user performing tests auth.is_logged_in() results in a True response.

However when continuing through the def user() the standard onlogin redirect doesn't forward to the main page indicating web2py isnt recording this as authentication accepted.

  1. I have also tried a redirect if "auth.is_logged_in()" but the decorators @auth.requires_login on the main page don't detect the login and redirect back to the login page.

Is this approach correct, I seem to be missing a step that knits the successful AWS login to Web2py

Chinh Dang

unread,
Sep 18, 2018, 10:50:26 AM9/18/18
to web...@googlegroups.com
Have you created a User Pool in Cognito to store the user profile? If you have configured it correctly, you should get a token when your app call Cognito to authenticate the credentials. If you get None response, there could be a configuration issue.

--
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 the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

kryto...@gmail.com

unread,
Sep 18, 2018, 11:32:15 AM9/18/18
to web...@googlegroups.com
Hi, yes the pool has been created successfully in AWS. When I use test units to test the code on the class the authentication works correctly and AWS responds with a Token.




Silvian Cedru

unread,
Feb 29, 2024, 5:48:47 AMFeb 29
to web2py-users
You still know how you did it ? 

Best Regards 
Reply all
Reply to author
Forward
0 new messages