Closed nok closed 9 months ago
I tested it and I can't reproduce what you described. Please give a working example to understand if there's an error. It might be related to your workflow or a third party library.
I had a similar issue and it was only with brave and chromium but it worked in Edge. It did randomly start preserving session data but something was creating a new session ID every page refresh SESSID would change and it shouldn't. I did however create a workaround when I was having issues with the sessions. I modified the redirect() method and has_invalid_state() method in the BaseDriver as follows (original method commented out):
def redirect(self, state=None):
if self.use_state():
# let user provide their own generated state
state = state or self.get_state()
# Store the state in a secure, HttpOnly cookie
self.application.make('response').cookie('oauth_state', state, http_only=True, secure=False, samesite='Lax')
else:
state = None
authorization_url = self.build_auth_url(state)
print(authorization_url)
response = self.application.make('response')
response.status(302)
response.header('Location', authorization_url)
return response
# def redirect(self, state=None):
# if self.use_state():
# # let user provide their own generated state
# state = state or self.get_state()
# # self.application.make("session").set("state", state)
# self.application.make("request").session.set("state", state)
#
# else:
# state = None
# authorization_url = self.build_auth_url(state)
# print(authorization_url)
# return self.application.make("response").redirect(location=authorization_url)
def has_invalid_state(self):
if self._is_stateless:
return False
# Retrieve the state from the cookie
state = self.application.make('request').cookie('oauth_state')
return state != self.application.make("request").input("state")
# def has_invalid_state(self):
# if self._is_stateless:
# return False
# state = self.application.make("session").get("state")
# return state != self.application.make("request").input("state")
@eaguad1337 whats the status of this? was it resolved? do you understand whats going on here?
@josephmancuso I couldn't reproduce the issue. The reporter didn't respond anymore.
will reopen if more info we can work on and replicate
Describe the bug
I want to access some data of Twitch users. For that a user has to connect over a Twitch application. To get an authorization code (for further steps) I have to pass a callback which will return the
code
and a passedstate
(for security reasons). The action from the controller which accepts the callback doesn't return any previous saved data from the session. It's empty. Because of that it's impossible to compare the saved and passed states.The following example shows the problem:
The (web) routes:
The
WelcomeController
:And the
welcome
view:This is an example of a
connect_url
: https://id.twitch.tv/oauth2/authorize?response_type=code&client_id=MY_CLIENT_ID&redirect_uri=https://my_app.local&scope=user:read:email&state=tyQsWmpJ2NTMYI37alequwThe prints of the workflow are here:
Expected behaviour
The session should keep the previous passed
state
. The prints should look like this:Steps to reproduce the bug
No response
Screenshots
No response
OS
macOS
OS version
Monterey 12.2
Browser
Chromium 120
Masonite Version
4.19.0
Anything else ?
No response