Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
funkwhale
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
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
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
techknowlogick
funkwhale
Commits
c8fcf1b0
Verified
Commit
c8fcf1b0
authored
5 years ago
by
Eliot Berriot
Browse files
Options
Downloads
Patches
Plain Diff
Support oauth token in URL
parent
e3b0efb2
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
api/config/settings/common.py
+1
-0
1 addition, 0 deletions
api/config/settings/common.py
api/funkwhale_api/users/oauth/server.py
+25
-0
25 additions, 0 deletions
api/funkwhale_api/users/oauth/server.py
api/tests/test_auth.py
+36
-0
36 additions, 0 deletions
api/tests/test_auth.py
with
62 additions
and
0 deletions
api/config/settings/common.py
+
1
−
0
View file @
c8fcf1b0
...
...
@@ -374,6 +374,7 @@ OAUTH2_PROVIDER = {
"
REFRESH_TOKEN_EXPIRE_SECONDS
"
:
3600
*
24
*
15
,
"
AUTHORIZATION_CODE_EXPIRE_SECONDS
"
:
5
*
60
,
"
ACCESS_TOKEN_EXPIRE_SECONDS
"
:
60
*
60
*
10
,
"
OAUTH2_SERVER_CLASS
"
:
"
funkwhale_api.users.oauth.server.OAuth2Server
"
,
}
OAUTH2_PROVIDER_APPLICATION_MODEL
=
"
users.Application
"
OAUTH2_PROVIDER_ACCESS_TOKEN_MODEL
=
"
users.AccessToken
"
...
...
This diff is collapsed.
Click to expand it.
api/funkwhale_api/users/oauth/server.py
0 → 100644
+
25
−
0
View file @
c8fcf1b0
import
urllib.parse
import
oauthlib.oauth2
class
OAuth2Server
(
oauthlib
.
oauth2
.
Server
):
def
verify_request
(
self
,
uri
,
*
args
,
**
kwargs
):
valid
,
request
=
super
().
verify_request
(
uri
,
*
args
,
**
kwargs
)
if
valid
:
return
valid
,
request
# maybe the token was given in the querystring?
query
=
urllib
.
parse
.
urlparse
(
request
.
uri
).
query
token
=
None
if
query
:
parsed_qs
=
urllib
.
parse
.
parse_qs
(
query
)
token
=
parsed_qs
.
get
(
"
token
"
,
[])
if
len
(
token
)
>
0
:
token
=
token
[
0
]
if
token
:
valid
=
self
.
request_validator
.
validate_bearer_token
(
token
,
request
.
scopes
,
request
)
return
valid
,
request
This diff is collapsed.
Click to expand it.
api/tests/test_
jwt_querystring
.py
→
api/tests/test_
auth
.py
+
36
−
0
View file @
c8fcf1b0
...
...
@@ -5,7 +5,7 @@ jwt_payload_handler = api_settings.JWT_PAYLOAD_HANDLER
jwt_encode_handler
=
api_settings
.
JWT_ENCODE_HANDLER
def
test_can_authenticate_using_token_param_in_url
(
factories
,
preferences
,
client
):
def
test_can_authenticate_using_
jwt_
token_param_in_url
(
factories
,
preferences
,
client
):
user
=
factories
[
"
users.User
"
]()
preferences
[
"
common__api_authentication_required
"
]
=
True
url
=
reverse
(
"
api:v1:tracks-list
"
)
...
...
@@ -17,3 +17,20 @@ def test_can_authenticate_using_token_param_in_url(factories, preferences, clien
token
=
jwt_encode_handler
(
payload
)
response
=
client
.
get
(
url
,
data
=
{
"
jwt
"
:
token
})
assert
response
.
status_code
==
200
def
test_can_authenticate_using_oauth_token_param_in_url
(
factories
,
preferences
,
client
,
mocker
):
mocker
.
patch
(
"
funkwhale_api.users.oauth.permissions.should_allow
"
,
return_value
=
True
)
token
=
factories
[
"
users.AccessToken
"
]()
preferences
[
"
common__api_authentication_required
"
]
=
True
url
=
reverse
(
"
api:v1:tracks-list
"
)
response
=
client
.
get
(
url
)
assert
response
.
status_code
==
401
response
=
client
.
get
(
url
,
data
=
{
"
token
"
:
token
.
token
})
assert
response
.
status_code
==
200
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