Django-oauth-toolkit: OAuth2TokenMiddleware does not work with Django 1.10

Created on 9 Aug 2016  Â·  23Comments  Â·  Source: jazzband/django-oauth-toolkit

Adding the OAuth2TokenMiddleware to the MIDDLEWARE array will break the application:
Traceback (most recent call last): ... File "/var/www/brownpapersession/dev/env-brownpapersession/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 82, in load_middleware mw_instance = middleware(handler) TypeError: object.__new__() takes no parameters

Mitigation described here: https://docs.djangoproject.com/en/1.10/topics/http/middleware/

Most helpful comment

There is a simple fix for this! Just edit the file /oauth2_provider/middleware.py
and add import statement:

from django.utils.deprecation import MiddlewareMixin

and change the class inheritance from "object" to "MiddlewareMixin"

For further details see the official Django 1.10 middleware migration page: https://docs.djangoproject.com/el/1.10/topics/http/middleware/#upgrading-pre-django-1-10-style-middleware

All 23 comments

great works!

I'm experiencing this issue as well.

not working for me.

when added it shows the following...

File "/home/apeiron/Proyectos/venvs/auth/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 82, in load_middleware
    mw_instance = middleware(handler)
TypeError: object() takes no parameters

@caxco93 Which Django version are you using?

@bastbnl I have the same issue (like a @caxco93) with Django 1.10

@szepczynski do you mean it doesn't work for you!

@bastbnl it doesn't work I got also this error (caused by OAuth2TokenMiddleware):

mw_instance = middleware(handler)
TypeError: object() takes no parameters

OK, thanks. I'll look into it and update the pull request

Op wo 26 okt. 2016 17:24 schreef Marcin Szepczyński <
[email protected]>:

@bastbnl https://github.com/bastbnl it doesn't work I got also this
error (caused by OAuth2TokenMiddleware):

mw_instance = middleware(handler)
TypeError: object() takes no parameters

—

You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/evonove/django-oauth-toolkit/issues/406#issuecomment-256381493,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AFoMs8Q3nZuKf9x-3KiKZynPdrTjKhvJks5q33CVgaJpZM4JgbXv
.

@szepczynski Could you tell me what happens when you try to run this import from the Django shell? (python manage.py shell):

from django.utils.deprecation import MiddlewareMixin

There is a simple fix for this! Just edit the file /oauth2_provider/middleware.py
and add import statement:

from django.utils.deprecation import MiddlewareMixin

and change the class inheritance from "object" to "MiddlewareMixin"

For further details see the official Django 1.10 middleware migration page: https://docs.djangoproject.com/el/1.10/topics/http/middleware/#upgrading-pre-django-1-10-style-middleware

Thanks for your reply. I understand that the easy fix will work on Django 1.10. I intended to create something that will work with Django 1.9 as well. Honesty never checked to see if this class exists on pre 1.10

I looked in the code and it seems that the class is present in django 1.9 aswell ;)

@Axenu You save my life. Thank you so much ^3^

@Axenu Just took a look into the 1.9 code on github and didn't see that class on the 1.9 tags. Then again, I don't really know about the deprecation strategy behind this app: should it still work on 1.8 as well? Or even 1.7? It's in the README, btw.

I'll take another look and attempt to improve the PR

I myself just took another look at it and it seems that it is not available in the earlier versions as I previously thought. I suppose another way to work around it would be to rewrite the class with a custom method:
def __call__(self, request): response = None if hasattr(self, 'process_request'): response = self.process_request(request) if not response: response = self.get_response(request) if hasattr(self, 'process_response'): response = self.process_response(request, response) return response
Which would satisfy the needs of the current Django version while still supporting the pervious versions. The code is taken directly from the midvlewaremixin class in Django 10.10.
It could be simplified a bit when added into the project.

Whats the status of this issue and #405? Is this library usable on 1.10 at all?

Seeing as the fix is simple and there hasnt been activity on it since August, I'm considering whether picking it for oauth support is the correct move.

@jleclanche I'm using this app on Django 1.10 with the patches I provided and I see it working properly. I believe it is a great app, but I feel the same. No maintainer comments on the PR and people are reporting issues on it, which I can't reproduce. Obviously improving it or fixing it gets hard

I say go for it as I haven't found anything that beats it

Yup. I like how everything works so far. But I agree, no patches or fixes for known Django 1.10 issues. Wonder what happened. @bastbnl @jleclanche

We're going to be using this app in prod pretty soon so we'll be maintaining a fork of this in git with the patch. If the maintainers (@synasius @Girbons) have disappeared, or are no longer maintaining this project, we'll make it more official but that's really something I want to avoid.

Heads up to @evonove: I can help maintain this project if needs be.

@jleclanche @niknokseyer @bastbnl any help is more than welcome! There are a lot of issues that still need to be triaged and PRs to be reviewed. We're trying to work on it on a regular basis, at least every two weeks, but I know it's not enough.

So let me know if any of you guys want to be added as a contributor with write permissions and I'll gladly do that. The only rule is that any "important" change or design choice should be discussed and reviewed together before it can be merged.

@synasius that's great. I'll keep an eye on the issues and see what I can do once I start using the lib in prod :)

Any chance for a release by the way now that it's 1.10 compatible?

@jleclanche sure! we need to address a couple of issues and then we'll release a new version

@synasius I'm now starting to work on the library for our project. I'd like write permissions if your offer still stands. My main goal will be to PR a cleaned up version of #395. I would also like to land a rebased #321 and triage all current issues that I can.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ashiksl picture ashiksl  Â·  3Comments

hackaprende picture hackaprende  Â·  5Comments

anuj9196 picture anuj9196  Â·  5Comments

IvanAnishchuk picture IvanAnishchuk  Â·  6Comments

lokilak picture lokilak  Â·  4Comments