FusionAuth
    • Home
    • Categories
    • Recent
    • Popular
    • Pricing
    • Contact us
    • Docs
    • Login

    Java Client JWT Validate returns incorrect exp/iat time

    Scheduled Pinned Locked Moved Unsolved
    Q&A
    2
    7
    835
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • N
      ndiarmand
      last edited by

      Hello,

      When using the java client library and calling 'fusionAuthClient.validateJWT(accessToken)' an incorrect exp/iat date is returned. When i validate the token using jwt.io for instance the expiration date is correct. This issue is similar to this: https://fusionauth.io/community/forum/topic/204/net-core-client-jwt-validate-returns-incorrect-exp-iat-time?_=1681918914102

      Is there any reason why this is happening?

      Here is an example of the text token:

      eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjQ4NmZlNDI0MiJ9.eyJhdWQiOiJlYjM2ZDFhYi00ZmVhLTQ5ZTMtYTI2Ny1jZmZiMTA0MjdhM2UiLCJleHAiOjE2ODE5OTQ4OTIsImlhdCI6MTY4MTk5MTI5MiwiaXNzIjoiYWNtZS5jb20iLCJzdWIiOiI4MGIyNDJlYi0zNmQ5LTRhMTEtODAwOC05YTQxYjc1OTFiMzUiLCJqdGkiOiI3MmRjZDA5My02OWQ0LTQ2Y2UtYTdiZi02NmJmOWM1ZWMzMjIiLCJhdXRoZW50aWNhdGlvblR5cGUiOiJQQVNTV09SRCIsImVtYWlsIjoiYWN0aWVmQGNiLm5sIiwiZW1haWxfdmVyaWZpZWQiOnRydWUsInByZWZlcnJlZF91c2VybmFtZSI6ImFjdGllZkBjYi5ubCIsImFwcGxpY2F0aW9uSWQiOiJlYjM2ZDFhYi00ZmVhLTQ5ZTMtYTI2Ny1jZmZiMTA0MjdhM2UiLCJyb2xlcyI6W10sInNpZCI6IjI5OTNjYTEzLWUwN2MtNDU1NS05ZWM3LWQ4NjU3ZmJlMzQwNSIsImF1dGhfdGltZSI6MTY4MTk5MTI5MiwidGlkIjoiYzNkMDkxODAtNTczNy0yMDcwLWY0NDItOTY0OWQ1ODQwMWM5In0.Sk5tXeDUG_RNhzKThvZkzK-xoQkQA5D62_QZJ-F1OLg
      
      danD 1 Reply Last reply Reply Quote 1
      • danD
        dan @ndiarmand
        last edited by

        @ndiarmand Here is the PR that fixed the .net client. I think we need to same logic in the java client, perhaps.

        https://github.com/FusionAuth/fusionauth-netcore-client/pull/49

        --
        FusionAuth - Auth for devs, built by devs.
        https://fusionauth.io

        danD 1 Reply Last reply Reply Quote 0
        • danD
          dan @dan
          last edited by

          Actually, looks like the java client uses https://github.com/FusionAuth/fusionauth-jwt/blob/master/src/main/java/io/fusionauth/jwt/json/ZonedDateTimeSerializer.java which should give the correct value.

          https://github.com/FusionAuth/fusionauth-jwt/blob/master/src/main/java/io/fusionauth/jwt/domain/JWT.java#L74

          Do you have a unit test you can share that I can take a closer look at?

          --
          FusionAuth - Auth for devs, built by devs.
          https://fusionauth.io

          1 Reply Last reply Reply Quote 0
          • N
            ndiarmand
            last edited by ndiarmand

            Hi Dan, here is a unit test that fails (JWT is supposed to be valid for 1 hour)

                @Test
                void testJWTValidity() {
                    FusionAuthClient fusionAuthClient = new FusionAuthClient(API_KEY, BASE_URL, TENANT_ID);
            
                    LoginRequest loginRequest = new io.fusionauth.domain.api.LoginRequest(UUID.fromString(APPLICATION_ID), EMAIL,
                            PASSWORD);
                    ClientResponse<LoginResponse, Errors> loginResponse = fusionAuthClient.login(loginRequest);
            
                    String token = loginResponse.getSuccessResponse().token;
                    ClientResponse<ValidateResponse, Void> validateResponse = fusionAuthClient.validateJWT(token);
            
                    assertFalse(validateResponse.getSuccessResponse().jwt.isExpired());
                }
            

            When i debug i see that the expiration date is wrong:

            b10ef12d-f2ed-4523-a7f2-5d6dcc9571ad-image.png

            I am using the latest version of the java client library (1.45.0)

            N 1 Reply Last reply Reply Quote 0
            • N
              ndiarmand @ndiarmand
              last edited by ndiarmand

              @dan added the unit test

              danD 1 Reply Last reply Reply Quote 0
              • danD
                dan @ndiarmand
                last edited by dan

                @ndiarmand Thanks, just saw this now. Filed a bug: https://github.com/FusionAuth/fusionauth-issues/issues/2275

                --
                FusionAuth - Auth for devs, built by devs.
                https://fusionauth.io

                danD 1 Reply Last reply Reply Quote 0
                • danD
                  dan @dan
                  last edited by

                  This has been fixed in version 1.46.0, which should be released soon.

                  You can track it at the issue above.

                  Thanks for reporting, @ndiarmand !

                  --
                  FusionAuth - Auth for devs, built by devs.
                  https://fusionauth.io

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post