Giter VIP home page Giter VIP logo

sanic-auth's People

Contributors

matsurih avatar pyx avatar stopspazzing avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

sanic-auth's Issues

How sanic-auth could be integrated into Bluteprints?

Hello,
I'm organizing my project into many different Blueprints(the routes), and all the routes(ENDPOINTS) can be accessed only after auth is done. I'm trying to utilize sanic-auth to help but just found the example given in the doc seems only applied to a centralized route file, say main.py. How sanic-auth could be integrated to the projects as mine which is composed of different Blueprints? Thank you!

Error when redirecting

When i try to access route with @login_required and it takes me to the auth page but after login it takes me back to route but without tag, so it throws 404 error. When i try to access the route with tag via url it makes me enter password again and i get stuck

User model not so agnostic...

The json mechanism you use right now is failing when the objects are BSON encoded python objects from MongoDB.

Ultimately it seems like Pickle would be a better solution and remove any issues with use-cases ...

On top of that it would be great if the entire user object was available on the session, sanic-auth didn't look for specific field names, and went about this in a more generic way since we can't always assume people can or will code their DB/User models to match.

thanks!

-k. noah

AttributeError: 'str' object has no attribute 'id'

[2022-04-21 22:44:38 +0300] [15964] [ERROR] Exception occurred while handling uri: 'http://127.0.0.1:5000/login' Traceback (most recent call last): File "handle_request", line 83, in handle_request ) File "C:\Users\Beliboba\PycharmProjects\beliboba\main.py", line 63, in login auth.login_user(request, user) File "C:\Users\Beliboba\PycharmProjects\beliboba\venv\lib\site-packages\sanic_auth\__init__.py", line 47, in login_user self.get_session(request)[self.auth_session_key] = self.serialize(user) File "C:\Users\Beliboba\PycharmProjects\beliboba\venv\lib\site-packages\sanic_auth\__init__.py", line 118, in serialize return {'uid': user.id, 'name': user.name} AttributeError: 'str' object has no attribute 'id' test test [2022-04-21 22:44:38 +0300] - (sanic.access)[INFO][127.0.0.1:53425]: POST http://127.0.0.1:5000/login 500 799
What do i need to do? User is stored in sqlite3 database

Using auth decorators in Class-Based Views

Sanic lets us use Decorators in Class based Views, this way. So, if my views are in views.py, how can I access the auth.decorator_name in those Classes?
Am having trouble importing the auth defined in my __init__.py, or am I doing it wrong.

__init__.py:

.
.
app = Sanic(__name__)
app.config.AUTH_LOGIN_ENDPOINT = 'login'
.
.
auth = Auth(app)

@auth.serializer
def serializer(user):
	return {'id':str(user.id),'email':user.email,'name':user.username}

@auth.user_loader
def user_loader(user):
	return user

app.add_route(Login.as_view(),'/login')
app.add_route(Register.as_view(),'/signup')

views.py:

class Dashboard(HTTPMethodView):
	# decorators = [auth.login_required]
	async def dashboard(self, request):
		pass

one client login, every client login. Is this the expected effect of examples?

1. test case

I use this examples:

  • ./examples/note.py
    // also tried another demo ./examples/blueprint/app.py

2. operation result

one browser ( chrome ) logged in,

then visit '/', found all other clients (firefox or curl) was loged in.

$ curl -sv 'http://localhost:8004'
* Connected to localhost (127.0.0.1) port 8004 (#0)
> GET / HTTP/1.1
> Host: localhost:8004
> User-Agent: curl/7.68.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Content-Length: 48
< Content-Type: text/html; charset=utf-8
< Connection: keep-alive
< Keep-Alive: 5
< 
* Connection #0 to host localhost left intact
<a href="/logout">Logout</a><p>Welcome, demo</p>

Is this the expected effect?
Am I miss some thing?



3. versions

tested on ubuntu 20.04

  • sanic 20.12.3 + python3.8
  • sanic 21.6.2 + python3.9

with

  • Sanic-Auth 0.3.0

sanic-auth no longer works with recent sanic/sanic_session

Not sure when this broke, but with sanic 20.3 and sanic_session 0.7 I'm getting

2020-05-30T17:40:47.800 ERROR handlers.py#140 Exception occurred while handling uri: 'http://192.168.20.55/'
Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/sanic/app.py", line 973, in handle_request
    response = await response
  File "/usr/lib/python3.8/site-packages/sanic_auth/__init__.py", line 93, in privileged
    user = self.current_user(request)
  File "/usr/lib/python3.8/site-packages/sanic_auth/__init__.py", line 61, in current_user
    token = self.get_session(request).get(self.auth_session_key, None)
  File "/usr/lib/python3.8/site-packages/sanic_auth/__init__.py", line 143, in get_session
    return request[self.session_name]
TypeError: 'Request' object is not subscriptable

AttributeError: 'list' object has no attribute 'ctx'

[2022-04-25 15:58:52 +0300] [8448] [ERROR] Exception occurred while handling uri: 'http://127.0.0.1:5000/login'
Traceback (most recent call last):
File "handle_request", line 83, in handle_request
)
File "C:\Users\Beliboba\PycharmProjects\beliboba\main.py", line 64, in login
auth.login_user(request, user=user)
File "C:\Users\Beliboba\PycharmProjects\beliboba\venv\lib\site-packages\sanic_auth_init_.py", line 47, in login_user
self.get_session(request)[self.auth_session_key] = self.serialize(user)
File "C:\Users\Beliboba\PycharmProjects\beliboba\venv\lib\site-packages\sanic_auth_init_.py", line 143, in get_session
return request.ctx.session
AttributeError: 'list' object has no attribute 'ctx'

Does sanic auth support perfectly for the multiple workers situation?

Hi pyx,
I have another issue want your help. I'm trying to use multiple workers(app.run(host="0.0.0.0", port=8000,workers=2,debug=True)) for the my app and using sanic-auth for user authentication, but encountering some issue, it requires me multiple several times login. When I change it to a single worker(host="0.0.0.0", port=8000,debug=True)), the problem solves. Any suggestion on that? Thank you!

sanic.exceptions.URLBuildError: Endpoint with name `auth.login` was not found

2017-06-01 16:56:42 - (sanic)[ERROR]: Exception occurred while handling uri: "http://127.0.0.1:8000/setup"
Traceback (most recent call last):
  File "/home/test/sanic/lib/python3.6/site-packages/sanic/app.py", line 471, in handle_request
    response = await response
  File "/usr/local/lib/python3.6/asyncio/coroutines.py", line 109, in __next__
    return self.gen.send(None)
  File "/home/test/PycharmProjects/Sanic-MDL-Blog/app/views.py", line 104, in setup
    auth.login_user(request, wform.username.data)
  File "/home/test/sanic/lib/python3.6/site-packages/sanic_auth/__init__.py", line 47, in login_user
    self.get_session(request)[self.auth_session_key] = self.serialize(user)
  File "/home/test/sanic/lib/python3.6/site-packages/sanic_auth/__init__.py", line 102, in serialize
    return {'uid': user.id, 'name': user.name}
AttributeError: 'str' object has no attribute 'id'

and

2017-06-01 17:10:17 - (sanic)[ERROR]: Traceback (most recent call last):
  File "/home/test/sanic/lib/python3.6/site-packages/sanic/app.py", line 471, in handle_request
    response = await response
  File "/usr/local/lib/python3.6/asyncio/coroutines.py", line 109, in __next__
    return self.gen.send(None)
  File "/home/test/sanic/lib/python3.6/site-packages/sanic_auth/__init__.py", line 87, in privileged
    u = self.login_url or request.app.url_for(self.login_endpoint)
  File "/home/test/sanic/lib/python3.6/site-packages/sanic/app.py", line 357, in url_for
    view_name))
sanic.exceptions.URLBuildError: Endpoint with name `auth.login` was not found

doesnt play well with sanic_session

doesnt play well with sanic_session while assigning user to request.ctx.session in the middleware.
user is not saved and manually saving is not working since auth takes over the session and user data is limited by this module.
have to fetch user data from the db by using the uid from the _auth and this makes two calls to the db.
im using MongoDBSessionInterface of the sanic_session

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.