Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
uffd2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
thies
uffd2
Commits
482727be
Commit
482727be
authored
3 years ago
by
Julian
Browse files
Options
Downloads
Patches
Plain Diff
Explain OAuth2 code/token customization hack
See
a59ee5f3
parent
0a78b45e
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
uffd/oauth2/views.py
+9
-0
9 additions, 0 deletions
uffd/oauth2/views.py
with
9 additions
and
0 deletions
uffd/oauth2/views.py
+
9
−
0
View file @
482727be
...
...
@@ -58,6 +58,10 @@ class UffdRequestValidator(oauthlib.oauth2.RequestValidator):
redirect_uri
=
oauthreq
.
redirect_uri
,
expires
=
expires
,
_scopes
=
'
'
.
join
(
oauthreq
.
scopes
))
db
.
session
.
add
(
grant
)
db
.
session
.
commit
()
# Oauthlib does not really provide a way to customize grant code generation.
# Actually `code` is created just before `save_authorization_code` is called
# and the same dict is later used to generate the OAuth2 response. So by
# modifing the `code` dict we can actually influence the grant code.
code
[
'
code
'
]
=
f
"
{
grant
.
id
}
-
{
code
[
'
code
'
]
}
"
def
validate_code
(
self
,
client_id
,
code
,
client
,
oauthreq
,
*
args
,
**
kwargs
):
...
...
@@ -94,6 +98,11 @@ class UffdRequestValidator(oauthlib.oauth2.RequestValidator):
)
db
.
session
.
add
(
tok
)
db
.
session
.
commit
()
# Oauthlib does not really provide a way to customize access/refresh token
# generation. Actually `token_data` is created just before
# `save_bearer_token` is called and the same dict is later used to generate
# the OAuth2 response. So by modifing the `token_data` dict we can actually
# influence the tokens.
token_data
[
'
access_token
'
]
=
f
"
{
tok
.
id
}
-
{
token_data
[
'
access_token
'
]
}
"
token_data
[
'
refresh_token
'
]
=
f
"
{
tok
.
id
}
-
{
token_data
[
'
refresh_token
'
]
}
"
return
oauthreq
.
client
.
default_redirect_uri
...
...
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