Skip to content

Commit

Permalink
fix: return 401 on unauthorized non-browser requests
Browse files Browse the repository at this point in the history
closes #115
  • Loading branch information
rokroskar committed Mar 14, 2019
1 parent a7a80ad commit a70c3a5
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 42 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pyyaml = ">=4.2b1"
[dev-packages]
chartpress = "*"
pylint = "*"
yapf = "*"

[requires]

Expand Down
83 changes: 41 additions & 42 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/notebooks_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ def decorated(*args, **kwargs):
if user:
return f(user, *args, **kwargs)
else:
# if the request is not coming from a browser, return 401
if request.is_xhr or request.environ['HTTP_ACCEPT'
] == 'application/json':
app.logger.info(
'Unauthorized non-browser request - returning 401.'
)
response = jsonify(error='An authorization token is required.'))
response.status_code = 401
return response

# redirect to login url on failed auth
state = auth.generate_state(next_url=request.path)
app.logger.debug(
Expand Down

0 comments on commit a70c3a5

Please sign in to comment.