Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
test_oauth2_django
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
test-it
test_oauth2_django
Commits
07cde8cf
Commit
07cde8cf
authored
Nov 06, 2017
by
Sharad Heft
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow a list of verifiers to check if users are valid.
parent
84eb1fe4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
1 deletion
+45
-1
test_oauth/backend.py
test_oauth/backend.py
+18
-1
test_oauth/verifiers.py
test_oauth/verifiers.py
+27
-0
No files found.
test_oauth/backend.py
View file @
07cde8cf
...
...
@@ -4,11 +4,16 @@ from django.contrib.auth.backends import ModelBackend
from
django.conf
import
settings
from
django.db
import
transaction
from
test_oauth
import
verifiers
from
test_oauth.models
import
TESTOAuth2Data
,
Character
from
test_oauth.session
import
TESTOAuth2Session
DEFAULT_VERIFIERS
=
[
verifiers
.
TESTMembershipVerifier
()
]
class
TESTOAuth2Backend
(
ModelBackend
):
def
authenticate
(
self
,
token
=
None
,
**
kwargs
):
if
token
is
None
:
...
...
@@ -16,6 +21,8 @@ class TESTOAuth2Backend(ModelBackend):
profile
=
TESTOAuth2Session
(
token
=
token
).
profile
self
.
run_verifiers
(
profile
)
user
,
_
=
get_user_model
().
objects
.
get_or_create
(
pk
=
profile
[
'id'
],
username
=
profile
[
'username'
]
...
...
@@ -44,6 +51,16 @@ class TESTOAuth2Backend(ModelBackend):
return
user
def
run_verifiers
(
self
,
profile
):
verifiers
=
getattr
(
settings
,
'TEST_OAUTH_VERIFIERS'
,
DEFAULT_VERIFIERS
)
for
v
in
verifiers
:
v
(
**
profile
)
def
get_user
(
self
,
user_id
):
UserModel
=
get_user_model
()
...
...
test_oauth/verifiers.py
0 → 100644
View file @
07cde8cf
from
django.core.exceptions
import
PermissionDenied
class
Verifier
(
object
):
def
__init__
(
self
,
**
kwargs
):
for
key
,
value
in
kwargs
.
items
():
setattr
(
self
,
key
,
value
)
def
__call__
(
self
,
**
kwargs
):
if
not
self
.
valid
(
**
kwargs
):
raise
PermissionDenied
(
self
.
message
)
class
GroupMembershipVerifier
(
Verifier
):
message
=
"You are not in the correct groups to log in to this site."
def
valid
(
self
,
groups
,
**
kwargs
):
for
g
in
groups
:
if
g
[
'id'
]
==
self
.
group
:
return
True
return
False
class
TESTMembershipVerifier
(
GroupMembershipVerifier
):
message
=
"You are not in TEST so you are not allowed to log in."
group
=
6
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