Skip to content

Commit

Permalink
Fix Starlette OAuth 2 client without request.session
Browse files Browse the repository at this point in the history
ref: #425
  • Loading branch information
lepture committed Feb 12, 2022
1 parent c13679f commit 1089d54
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions authlib/integrations/starlette_client/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ class StarletteAppMixin(object):
async def save_authorize_data(self, request, **kwargs):
state = kwargs.pop('state', None)
if state:
await self.framework.set_state_data(request.session, state, kwargs)
if self.framework.cache:
session = None
else:
session = request.session
await self.framework.set_state_data(session, state, kwargs)
else:
raise RuntimeError('Missing state value')

Expand Down Expand Up @@ -60,7 +64,12 @@ async def authorize_access_token(self, request, **kwargs):
'state': request.query_params.get('state'),
}

state_data = await self.framework.get_state_data(request.session, params.get('state'))
if self.framework.cache:
session = None
else:
session = request.session

state_data = await self.framework.get_state_data(session, params.get('state'))
params = self._format_state_params(state_data, params)
token = await self.fetch_access_token(**params, **kwargs)

Expand Down

0 comments on commit 1089d54

Please sign in to comment.