-
Notifications
You must be signed in to change notification settings - Fork 317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix 'WSGIRequest' object does not support item assignment error #152
base: master
Are you sure you want to change the base?
Conversation
- Delete request arguments in functions. It is redundant as the first argument is usually the request object - Call the session method on the request object (web_app_session.session). This fixes `self.session[self.csrf_token_session_key] = csrf_token` error
Thanks! |
@starforever might I also suggest changing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the error happens when you pass in an object for web_app_session
which should actually be a dict
.
I think we should keep these parameters simple, rather than making them some objects with fields like session
or query_params
without explicitly specifying how they are constructed. This makes it easier for others to understand the example code regardless of what libraries they use for building requests.
try: | ||
oauth_result = \\ | ||
get_dropbox_auth_flow(web_app_session).finish( | ||
get_dropbox_auth_flow(web_app_session.session).finish( | ||
request.query_params) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you remove request
you need to find proper replacement for all its usages within the function. Otherwise the code will break.
Ok, I think I understand. DropboxOAuth2Flow class needs to take in web_app_session. However, the documentation would be wrong for Django's implementation because the URL handlers for It is that request's session ( My point is, Therefore for Django: def get_dropbox_auth_flow(web_app_session):
redirect_uri = "https://my-web-server.org/dropbox-auth-finish"
return DropboxOAuth2Flow(
APP_KEY, APP_SECRET, redirect_uri, web_app_session,
"dropbox-auth-csrf-token")
# URL handler for /dropbox-auth-start
def dropbox_auth_start(request):
authorize_url = get_dropbox_auth_flow(request.session).start()
redirect_to(authorize_url)
# URL handler for /dropbox-auth-finish
def dropbox_auth_finish(request):
try:
oauth_result = \
get_dropbox_auth_flow(request.session).finish(
request.query_params)
except BadRequestException, e:
http_status(400)
... For Flask, session is global. We would just need to access it directly: from flask import session, request
def get_dropbox_auth_flow(web_app_session):
redirect_uri = "https://my-web-server.org/dropbox-auth-finish"
return DropboxOAuth2Flow(
APP_KEY, APP_SECRET, redirect_uri, web_app_session,
"dropbox-auth-csrf-token")
# URL handler for /dropbox-auth-start
@app.route('/dropbox-auth-start')
def dropbox_auth_start():
authorize_url = get_dropbox_auth_flow(session).start()
redirect_to(authorize_url)
# URL handler for /dropbox-auth-finish
@app.route('/dropbox-auth-finish')
def dropbox_auth_finish():
try:
oauth_result = \
get_dropbox_auth_flow(session).finish(
request.query_params)
except BadRequestException, e:
http_status(400)
... The documentation specified two arguments, I think with Django's implementation, implementing for Flask would be clear and straightforward to a newbie. |
Hello, is this something you are still interested in working on? |
Sure @rogebrd. I'll take a look at the failing test |
|
self.session[self.csrf_token_session_key] = csrf_token
error