diff --git a/AUTHORS b/AUTHORS index 2d3f80527..cf61dff0a 100644 --- a/AUTHORS +++ b/AUTHORS @@ -11,6 +11,7 @@ Abhishek Patel Adam Johnson Adam ZahradnĂ­k Adheeth P Praveen +Aibek Prenov Alan Crosswell Alan Rominger Alejandro Mantecon Guillen diff --git a/CHANGELOG.md b/CHANGELOG.md index 32dd1734c..214070dc7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * #1584 Fix IDP container in docker compose environment could not find templates and static files. * #1562 Fix: Handle AttributeError in IntrospectTokenView * #1583 Fix: Missing pt_BR translations +* #1597 Fix: TypeError at /s/auth/o/token/ diff --git a/oauth2_provider/oauth2_validators.py b/oauth2_provider/oauth2_validators.py index db459a446..fc50352b8 100644 --- a/oauth2_provider/oauth2_validators.py +++ b/oauth2_provider/oauth2_validators.py @@ -867,12 +867,16 @@ def get_id_token_dictionary(self, token, token_handler, request): claims = self.get_oidc_claims(token, token_handler, request) expiration_time = timezone.now() + timedelta(seconds=oauth2_settings.ID_TOKEN_EXPIRE_SECONDS) + if request.user.last_login: + auth_time = int(dateformat.format(request.user.last_login, "U")) + else: + auth_time = int(timezone.now().timestamp()) # Required ID Token claims claims.update( **{ "iss": self.get_oidc_issuer_endpoint(request), "exp": int(dateformat.format(expiration_time, "U")), - "auth_time": int(dateformat.format(request.user.last_login, "U")), + "auth_time": auth_time, "jti": str(uuid.uuid4()), } ) diff --git a/tests/test_oauth2_validators.py b/tests/test_oauth2_validators.py index 14c74506e..ad23b64f1 100644 --- a/tests/test_oauth2_validators.py +++ b/tests/test_oauth2_validators.py @@ -60,6 +60,8 @@ def always_invalid_token(): class TestOAuth2Validator(TransactionTestCase): def setUp(self): self.user = UserModel.objects.create_user("user", "test@example.com", "123456") + self.user.last_login = None + self.user.save() self.request = mock.MagicMock(wraps=Request) self.request.user = self.user self.request.grant_type = "not client"