Skip to content

Commit fe262b8

Browse files
committed
resolves root session issue in security policy, removes hack solution in session model
1 parent ea2650e commit fe262b8

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

h/security/policy/combined.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ def _call_sub_policies(self, method, request, *args, **kwargs):
7474
return getattr(self._ui_policy, method)(request, *args, **kwargs)
7575

7676
# Then we try the bearer header (or `access_token` GET param)
77+
7778
result = getattr(self._bearer_token_policy, method)(request, *args, **kwargs)
79+
print(result)
7880

7981
if not result and self._http_basic_auth_policy.handles(request):
8082
# Only then do we look for auth clients authenticating with basic
@@ -87,7 +89,9 @@ def _call_sub_policies(self, method, request, *args, **kwargs):
8789

8890
@staticmethod
8991
def _is_api_request(request):
90-
return request.path.startswith("/api") and request.path not in [
92+
return (request.path.startswith("/api") or request.path.startswith("/hypothesis")) and request.path not in [
9193
"/api/token",
9294
"/api/badge",
95+
"/hypothesis/api/token",
96+
"/hypothesis/api/badge"
9397
]

h/session.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@ def profile(request, authority=None):
2525
"""
2626
user = request.user
2727

28-
if user is None:
29-
h_key = request.cookies.get('h_key')
30-
user_svc = request.find_service(name='user')
31-
user_tosdr = user_svc.fetch_from_tosdr(h_key)
32-
username = user_tosdr.username
33-
user = user_svc.fetch(username, authority=request.default_authority)
34-
3528
if user is not None:
3629
authority = user.authority
3730
else:

h/views/api/auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def _authorized_response(self):
167167
username = user_tosdr.username
168168
user = self.user_svc.fetch(username, authority=self.request.default_authority)
169169
# TOSDR : create user in h if it does not exist
170-
if not user:
170+
if h_key and not user:
171171
password = ''.join(random.choice(string.printable) for i in range(12))
172172
user = User(username=user_tosdr.username, email=user_tosdr.email, privacy_accepted=datetime.now(), comms_opt_in=False, password=password, authority=self.request.default_authority)
173173
self.session.add(user)

0 commit comments

Comments
 (0)