-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
REST endpoints send incomplete WWW-Authenticate header on 401 #1825
Comments
If you look at the DRF documentation for authentication you'll see that this middleware is what implements the header scheme with the word Since we're relying on a well-established third party library for this, I don't think this can be considered a bug, especially not within our codebase. To more closely address your problem: can you simply create a mechanism to authenticate to DANDI using the |
My summary of further discussion on slack: agreement that there is a bug somewhere that we are responding with
while not following OAuth 2.0 for bearer token authentication. DRF and page linked says it should be the
in such a case. Is it the location where we specify the authenticator? https://github.com/dandi/dandi-archive/blob/HEAD/dandiapi/settings.py#L56 |
FWIW, if I am correct about that location about possible auth schemes, then may be to support also the class CustomKeywordTokenAuthentication(TokenAuthentication):
keyword = 'Bearer' PS edits
|
ATM non-authenticated request is receiving 401 response with "Bearer" as the auth-scheme: ❯ curl --verbose -J -L -X 'GET' 'http://localhost:8000/api/assets/ac212d93-525a-4454-afdd-85b90aad6143/download/' 2>&1 | grep WW-A < WWW-Authenticate: Bearer realm="api" But according to the https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication#authentication_schemes and in particular https://datatracker.ietf.org/doc/html/rfc6750 for such request client should provide "Authorization: Bearer KEY" not "Authorization: token KEY". This commit adds support for both so we could follow the standard and retain support of already implemented client solutions. Such approach is also taken by GitHub API: https://docs.github.com/en/rest/authentication/authenticating-to-the-rest-api?apiVersion=2022-11-28 Verification of functionality: ❯ curl -J -L -X 'GET' 'http://localhost:8000/api/assets/ac212d93-525a-4454-afdd-85b90aad6143/download/' {"detail":"Authentication credentials were not provided."}% ❯ curl -J -L -X 'GET' 'http://localhost:8000/api/assets/ac212d93-525a-4454-afdd-85b90aad6143/download/?content_disposition=attachment' -H 'Authorization: Bearer 21a587dff19ec6956364443b97414d8bb4331b09' MYDATA ❯ curl -J -L -X 'GET' 'http://localhost:8000/api/assets/ac212d93-525a-4454-afdd-85b90aad6143/download/?content_disposition=attachment' -H 'Authorization: token 21a587dff19ec6956364443b97414d8bb4331b09' MYDATA ❯ curl -J -L -X 'GET' 'http://localhost:8000/api/assets/ac212d93-525a-4454-afdd-85b90aad6143/download/?content_disposition=attachment' -H 'Authorization: Token 21a587dff19ec6956364443b97414d8bb4331b09' MYDATA ❯ curl -J -L -X 'GET' 'http://localhost:8000/api/assets/ac212d93-525a-4454-afdd-85b90aad6143/download/?content_disposition=attachment' -H 'Authorization: dragon 21a587dff19ec6956364443b97414d8bb4331b09' {"detail":"Authentication credentials were not provided."} Closes #1825
ATM non-authenticated request is receiving 401 response with "Bearer" as the auth-scheme: ❯ curl --verbose -J -L -X 'GET' 'http://localhost:8000/api/assets/ac212d93-525a-4454-afdd-85b90aad6143/download/' 2>&1 | grep WW-A < WWW-Authenticate: Bearer realm="api" But according to the https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication#authentication_schemes and in particular https://datatracker.ietf.org/doc/html/rfc6750 for such request client should provide "Authorization: Bearer KEY" not "Authorization: token KEY". This commit adds support for both so we could follow the standard and retain support of already implemented client solutions. Such approach is also taken by GitHub API: https://docs.github.com/en/rest/authentication/authenticating-to-the-rest-api?apiVersion=2022-11-28 Verification of functionality: ❯ curl -J -L -X 'GET' 'http://localhost:8000/api/assets/ac212d93-525a-4454-afdd-85b90aad6143/download/' {"detail":"Authentication credentials were not provided."}% ❯ curl -J -L -X 'GET' 'http://localhost:8000/api/assets/ac212d93-525a-4454-afdd-85b90aad6143/download/?content_disposition=attachment' -H 'Authorization: Bearer 21a587dff19ec6956364443b97414d8bb4331b09' MYDATA ❯ curl -J -L -X 'GET' 'http://localhost:8000/api/assets/ac212d93-525a-4454-afdd-85b90aad6143/download/?content_disposition=attachment' -H 'Authorization: token 21a587dff19ec6956364443b97414d8bb4331b09' MYDATA ❯ curl -J -L -X 'GET' 'http://localhost:8000/api/assets/ac212d93-525a-4454-afdd-85b90aad6143/download/?content_disposition=attachment' -H 'Authorization: Token 21a587dff19ec6956364443b97414d8bb4331b09' MYDATA ❯ curl -J -L -X 'GET' 'http://localhost:8000/api/assets/ac212d93-525a-4454-afdd-85b90aad6143/download/?content_disposition=attachment' -H 'Authorization: dragon 21a587dff19ec6956364443b97414d8bb4331b09' {"detail":"Authentication credentials were not provided."} Closes #1825
ok, I have a recipe on how to proceed:
this script does it and shows all needed steps#!/bin/bash
cd "$(mktemp -d ${TMPDIR:-/tmp}/dl-XXXXXXX)"
set -eux
git init
git annex init
# generate config to ship along
mkdir -p .datalad/providers
cat >| .datalad/providers/dandi.cfg << EOF
[provider:dandi]
url_re = https?://api\.dandiarchive\.org/api/.*
authentication_type = http_token
credential = dandi
[credential:dandi]
type = token
EOF
git add .datalad/providers/dandi.cfg; git commit -m 'Added dandi provider config'
git annex initremote datalad type=external externaltype=datalad encryption=none autoenable=true
git annex addurl --file dataset_description.json https://api.dandiarchive.org/api/dandisets/000403/versions/draft/assets/0cb481e5-b979-4eed-8ea4-9cd0d78276a3/download/
cat dataset_description.json
git annex whereis |
I have opened a PR to fix this in DRF. However, I'm going to close this as unplanned for the following reasons:
@yarikoptic, let me know if there is more to discuss here. |
ATM (same example as in #1824 ):
and for that (Bearer) scheme I see https://datatracker.ietf.org/doc/html/rfc6750#section-2.1 listing
whenever we seems to be using
token
notBearer
:and if I specify as
Bearer
-- no good:In DataLad we are using
Bearer
keyword there and hence our implementation for this authorization scheme (https://github.com/datalad/datalad/blob/HEAD/datalad/downloaders/http.py#L401) is not working. It works if I change in our code "Bearer" to "token" but it seems to be invalid and I think the quickest fix would be for dandi-archive to add support for having "Bearer" specified in addition to "token" and slowly (after we have our dandi-cli etc) deprecated "token".The text was updated successfully, but these errors were encountered: