izdi / django-slack-oauth

Handles OAuth and stores slack token
MIT License
53 stars 26 forks source link

Context in SLACK_SUCCESS_REDIRECT_URL #25

Open ianmobbs opened 5 years ago

ianmobbs commented 5 years ago

Hi @izdi,

Thanks for the awesome package! I've been using it in a personal project, but I'm unsure of how to access the current users Slack information in the SLACK_SUCCESS_REDIRECT_URL. While it is being stored in the database, getting the "most recently created access token" after redirection seems to introduce all sorts of race conditions. When checking request.user in the redirected view, all it displays is AnonymousUser. I assumed any information set on the request object would be available, but it looks like creating a new HttpResponseRedirect (views.py#L117) also creates a new request object, wiping any information stored on it from your pipelines. What's your recommended solution to this problem?

Thanks!

ianmobbs commented 5 years ago

Would still love a response, but here's how I solved in in the meantime: I created a custom SlackUser object with a session attribute, and as the first part of my pipeline I get_or_create a new SlackUser then update the session attribute using request.COOKIES['session']. After redirecting to SLACK_SUCCESS_REDIRECT_URL, I get the SlackUser with the same session!