Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
api
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
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
cubicweb
cubes
api
Commits
ca3549d807d6
Commit
ca3549d807d6
authored
2 years ago
by
Arnaud Vergnet
Browse files
Options
Downloads
Patches
Plain Diff
feat(jwt): allow setting custom settings paths
parent
d9a956e51cc4
No related branches found
No related tags found
1 merge request
!6
feat: add jwt authentication
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cubicweb_api/jwt_auth.py
+16
-8
16 additions, 8 deletions
cubicweb_api/jwt_auth.py
with
16 additions
and
8 deletions
cubicweb_api/jwt_auth.py
+
16
−
8
View file @
ca3549d8
...
...
@@ -9,5 +9,7 @@
log
=
logging
.
getLogger
(
__name__
)
def
create_jwt_policy
(
config
:
Configurator
,
prefix
=
"
cubicweb.auth.jwt
"
):
def
create_jwt_policy
(
config
:
Configurator
,
prefix
=
"
cubicweb.auth.jwt
"
,
custom_paths
:
dict
=
None
):
cfg
=
config
.
registry
.
settings
...
...
@@ -13,7 +15,4 @@
cfg
=
config
.
registry
.
settings
private_key_string
=
prefix
+
"
.private_key
"
if
private_key_string
not
in
cfg
:
raise
KeyError
(
private_key_string
)
keys
=
(
"
private_key
"
,
"
public_key
"
,
...
...
@@ -23,5 +22,13 @@
"
http_header
"
,
"
auth_type
"
,
)
key_paths
=
{}
if
custom_paths
is
None
:
custom_paths
=
{}
for
k
in
keys
:
key_paths
[
k
]
=
custom_paths
.
get
(
k
,
"
{}.{}
"
.
format
(
prefix
,
k
))
# private key is mandatory
if
key_paths
[
"
private_key
"
]
not
in
cfg
:
raise
KeyError
(
key_paths
[
"
private_key
"
])
kwargs
=
{}
for
k
in
keys
:
...
...
@@ -26,8 +33,7 @@
kwargs
=
{}
for
k
in
keys
:
key_path
=
"
{}.{}
"
.
format
(
prefix
,
k
)
if
key_path
in
cfg
:
kwargs
[
k
]
=
cfg
.
get
(
key_path
)
if
key_paths
[
k
]
in
cfg
:
kwargs
[
k
]
=
cfg
.
get
(
key_paths
[
k
])
auth_policy
=
JWTAuthenticationPolicy
(
**
kwargs
)
cookie_policy
=
JWTCookieAuthenticationPolicy
.
make_from
(
auth_policy
,
cookie_name
=
"
CW_JWT
"
,
https_only
=
True
,
reissue_time
=
7200
...
...
@@ -55,7 +61,9 @@
def
setup_jwt
(
config
:
Configurator
):
config
.
include
(
"
pyramid_jwt
"
)
try
:
policy
=
create_jwt_policy
(
config
)
policy
=
create_jwt_policy
(
config
,
custom_paths
=
{
"
private_key
"
:
"
cubicweb.auth.authtkt.session.secret
"
}
)
except
KeyError
as
e
:
log
.
warning
(
"
Could not configure JWT policy: missing configuration key %s
"
,
str
(
e
)
...
...
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