Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
djangoldp-account
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
djangoldp-packages
djangoldp-account
Commits
94df4711
Commit
94df4711
authored
5 months ago
by
Benoit Alessandroni
Browse files
Options
Downloads
Patches
Plain Diff
feature: add bearer auth backend
parent
4a8e30bf
No related branches found
No related tags found
1 merge request
!120
feature: add bearer auth backend
Pipeline
#18859
failed
5 months ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
djangoldp_account/auth/backends.py
+27
-0
27 additions, 0 deletions
djangoldp_account/auth/backends.py
djangoldp_account/settings.py
+5
-1
5 additions, 1 deletion
djangoldp_account/settings.py
with
32 additions
and
1 deletion
djangoldp_account/auth/backends.py
+
27
−
0
View file @
94df4711
...
@@ -168,3 +168,30 @@ class ExternalUserBackend(ModelBackend):
...
@@ -168,3 +168,30 @@ class ExternalUserBackend(ModelBackend):
# make an attempt assuming Bearer token if not recognised or not specified
# make an attempt assuming Bearer token if not recognised or not specified
return
self
.
validate_bearer_token
(
jwt
)
return
self
.
validate_bearer_token
(
jwt
)
class
BearerAuthBackend
(
AllowAllUsersModelBackend
):
def
validate_bearer_token
(
self
,
token
):
try
:
token
=
Token
.
objects
.
get
(
access_token
=
token
)
if
token
:
owner
=
token
.
client
.
owner
if
self
.
user_can_authenticate
(
owner
):
return
owner
except
Exception
as
e
:
raise
e
return
None
def
authenticate
(
self
,
request
,
*
args
,
**
kwargs
):
if
"
HTTP_AUTHORIZATION
"
in
request
.
META
:
jwt
=
request
.
META
[
"
HTTP_AUTHORIZATION
"
]
if
jwt
.
lower
().
startswith
(
"
bearer
"
):
jwt
=
jwt
[
7
:]
# make an attempt assuming Bearer token if not recognised or not specified
return
self
.
validate_bearer_token
(
jwt
)
return
ModelBackend
().
authenticate
(
request
,
*
args
,
**
kwargs
)
This diff is collapsed.
Click to expand it.
djangoldp_account/settings.py
+
5
−
1
View file @
94df4711
def
userinfo
(
claims
,
user
):
def
userinfo
(
claims
,
user
):
# Populate claims dict.
# Populate claims dict.
if
not
user
:
return
claims
claims
[
'
name
'
]
=
'
{0} {1}
'
.
format
(
user
.
first_name
,
user
.
last_name
)
claims
[
'
name
'
]
=
'
{0} {1}
'
.
format
(
user
.
first_name
,
user
.
last_name
)
claims
[
'
email
'
]
=
user
.
email
claims
[
'
email
'
]
=
user
.
email
claims
[
'
website
'
]
=
user
.
urlid
claims
[
'
website
'
]
=
user
.
urlid
...
@@ -8,4 +11,5 @@ def userinfo(claims, user):
...
@@ -8,4 +11,5 @@ def userinfo(claims, user):
return
claims
return
claims
def
sub_generator
(
user
):
def
sub_generator
(
user
):
return
user
.
urlid
if
user
:
return
user
.
urlid
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment