Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
35022ca9
Commit
35022ca9
authored
Jun 29, 2013
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor SessionAuthentication slightly
parent
f7db0695
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
9 deletions
+15
-9
rest_framework/authentication.py
+15
-9
No files found.
rest_framework/authentication.py
View file @
35022ca9
...
...
@@ -26,6 +26,12 @@ def get_authorization_header(request):
return
auth
class
CSRFCheck
(
CsrfViewMiddleware
):
def
_reject
(
self
,
request
,
reason
):
# Return the failure reason instead of an HttpResponse
return
reason
class
BaseAuthentication
(
object
):
"""
All authentication classes should extend BaseAuthentication.
...
...
@@ -110,20 +116,20 @@ class SessionAuthentication(BaseAuthentication):
if
not
user
or
not
user
.
is_active
:
return
None
# Enforce CSRF validation for session based authentication.
class
CSRFCheck
(
CsrfViewMiddleware
):
def
_reject
(
self
,
request
,
reason
):
# Return the failure reason instead of an HttpResponse
return
reason
self
.
enforce_csrf
(
http_request
)
# CSRF passed with authenticated user
return
(
user
,
None
)
reason
=
CSRFCheck
()
.
process_view
(
http_request
,
None
,
(),
{})
def
enforce_csrf
(
self
,
request
):
"""
Enforce CSRF validation for session based authentication.
"""
reason
=
CSRFCheck
()
.
process_view
(
request
,
None
,
(),
{})
if
reason
:
# CSRF failed, bail with explicit error message
raise
exceptions
.
AuthenticationFailed
(
'CSRF Failed:
%
s'
%
reason
)
# CSRF passed with authenticated user
return
(
user
,
None
)
class
TokenAuthentication
(
BaseAuthentication
):
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment