Skip to content
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

Fixed simple jwt env usage and settings #318

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions resources/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ def get_auth(user, **extra):
token = AccessToken.for_user(user)
if 'exp' in extra:
token.set_exp(from_time=extra['exp'])
if 'token_type' in extra:
token.token_type = extra['token_type']

return 'JWT %s' % str(token)

def authenticated_post(self, url, data, **extra):
Expand Down Expand Up @@ -112,16 +111,10 @@ def test_api(self):
#self.assertContains(response, '"ends":"' + end.isoformat())

def test_jwt_expired(self):
exp = datetime.datetime.utcnow() - datetime.timedelta(minutes=15)
exp = datetime.datetime.utcnow() - datetime.timedelta(minutes=16)
response = self.authenticated_post('/v1/reservation/', {}, exp=exp)
self.assertEqual(response.status_code, 401)

def test_jwt_invalid_token_type(self):
response = self.authenticated_post('/v1/reservation/', {},
token_type=generate_random_string(6))
self.assertEqual(response.status_code, 400)



@pytest.mark.skip(reason="availability disabled for now")
class AvailableAPITestCase(APITestCase, JWTMixin):
Expand Down
8 changes: 3 additions & 5 deletions respa/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
MACHINE_TO_MACHINE_AUTH_ENABLED=(bool, False),
JWT_AUTH_HEADER_PREFIX=(str, "JWT"),
JWT_LEEWAY=(int, 30), # seconds
JWT_LIFETIME=(int, 3600), # generated jwt token expires after this many seconds
JWT_LIFETIME=(int, 900), # generated jwt token expires after this many seconds
JWT_PAYLOAD_HANDLER=(str, 'respa.machine_to_machine_auth.utils.jwt_payload_handler'), # generates jwt token payload
ENABLE_RESOURCE_TOKEN_AUTH=(bool, False),
DISABLE_SERVER_SIDE_CURSORS=(bool, False),
Expand Down Expand Up @@ -425,13 +425,11 @@
}

SIMPLE_JWT = {
'AUTH_HEADER_TYPES': ('JWT', ),
'AUTH_HEADER_TYPES': env('JWT_AUTH_HEADER_PREFIX'),
'LEEWAY': env('JWT_LEEWAY'),
'AUDIENCE': env('TOKEN_AUTH_ACCEPTED_AUDIENCE'),
'SIGNING_KEY': env('TOKEN_AUTH_SHARED_SECRET'),
'AUTH_HEADER_PREFIX': env('JWT_AUTH_HEADER_PREFIX'),
'EXPIRATION_DELTA': datetime.timedelta(seconds=env('JWT_LIFETIME')),
'PAYLOAD_HANDLER': env('JWT_PAYLOAD_HANDLER')
'ACCESS_TOKEN_LIFETIME': datetime.timedelta(seconds=env('JWT_LIFETIME')),
}

# toggles auth token api endpoint url
Expand Down
Loading