1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-31 06:51:10 +03:00

Merge pull request #2298 from ryanpetrello/fix-oauth2-deprecated-token-header

properly support deprecated `Authorization: Token xyz`
This commit is contained in:
Ryan Petrello 2018-09-24 15:15:13 -04:00 committed by GitHub
commit 8a66213dbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View File

@ -257,6 +257,9 @@ class DeprecatedAuthTokenMiddleware(object):
'be replaced with OAuth2.0 in the next version of Ansible Tower '
'(see /api/o/ for more details).'
)
elif request.environ.get('HTTP_AUTHORIZATION', '').startswith('Token '):
token = request.environ['HTTP_AUTHORIZATION'].split(' ', 1)[-1].strip()
request.environ['HTTP_AUTHORIZATION'] = six.text_type('Bearer {}').format(token)
class MigrationRanCheckMiddleware(object):

View File

@ -380,6 +380,15 @@ def test_deprecated_authtoken_support(alice, fmt):
assert resp.data['refresh_token'] is None
assert resp.data['scope'] == 'write'
for _type in ('Token', 'Bearer'):
request = getattr(APIRequestFactory(), 'get')(
'/api/v2/me/',
HTTP_AUTHORIZATION=' '.join([_type, resp.data['token']])
)
DeprecatedAuthTokenMiddleware().process_request(request)
view, view_args, view_kwargs = resolve(request.path)
assert view(request, *view_args, **view_kwargs).status_code == 200
@pytest.mark.django_db
def test_deprecated_authtoken_invalid_username(alice):