From c799645658c21680a56cab4e0f0c238e2f38de18 Mon Sep 17 00:00:00 2001 From: Tim Chamberlain Date: Wed, 3 May 2023 09:29:20 -0500 Subject: [PATCH] CTLE-421: updated to check expiration and to get auth0 access token the correct way --- .../Auth0AuthenticationModule.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/modules/authentication/implementations/Auth0AuthenticationModule.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/modules/authentication/implementations/Auth0AuthenticationModule.java index 68b0dd0a..315cff73 100644 --- a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/modules/authentication/implementations/Auth0AuthenticationModule.java +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/modules/authentication/implementations/Auth0AuthenticationModule.java @@ -812,8 +812,10 @@ public class Auth0AuthenticationModule implements QAuthenticationModuleInterface { DecodedJWT jwt = JWT.decode(accessToken); String payload = jwt.getPayload(); - System.out.println("IOK"); - needNewToken = false; + if(jwt.getExpiresAtAsInstant().isAfter(Instant.now())) + { + needNewToken = false; + } } if(needNewToken) @@ -833,7 +835,16 @@ public class Auth0AuthenticationModule implements QAuthenticationModuleInterface QRecord clientAuth0Application = new GetAction().execute(getInput).getRecord(); String clientId = clientAuth0Application.getValueString(metaData.getAuth0ClientIdField()); String clientSecret = clientAuth0Application.getValueString(metaData.getAuth0ClientSecretField()); - accessToken = createAccessToken(metaData, clientId, clientSecret); + + ///////////////////////////////////////////////////////////////////////////////////////////////// + // request access token from auth0 if exception is not thrown, that means 200OK, we want to // + // store the actual access token in the database, and return a unique value // + // back to the user which will be what they use on subsequent requests (because token too big) // + ///////////////////////////////////////////////////////////////////////////////////////////////// + JSONObject accessTokenData = requestAccessTokenFromAuth0(metaData, clientId, clientSecret); + + Integer expiresInSeconds = accessTokenData.getInt("expires_in"); + accessToken = accessTokenData.getString("access_token"); ////////////////////////////////////////////////////////// // update the api key record and store new access token //