diff --git a/qqq-backend-core/pom.xml b/qqq-backend-core/pom.xml
index 87a88d69..5e795411 100644
--- a/qqq-backend-core/pom.xml
+++ b/qqq-backend-core/pom.xml
@@ -167,6 +167,13 @@
test
+
+ org.mockito
+ mockito-core
+ 4.8.1
+ test
+
+
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 29f5b62c..69ef1fe6 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
@@ -193,7 +193,7 @@ public class Auth0AuthenticationModule implements QAuthenticationModuleInterface
/*******************************************************************************
**
*******************************************************************************/
- private static String getIdTokenFromBase64BasicAuthCredentials(AuthAPI auth, String base64Credentials) throws Auth0Exception
+ private String getIdTokenFromBase64BasicAuthCredentials(AuthAPI auth, String base64Credentials) throws Auth0Exception
{
////////////////////////////////////////////////////////////////////////////////
// look for a fresh idToken in the state provider for this set of credentials //
@@ -211,9 +211,25 @@ public class Auth0AuthenticationModule implements QAuthenticationModuleInterface
}
}
+ //////////////////////////////////////////////////////////////////////////////
+ // not found in cache, make request to auth0 and cache the returned idToken //
+ //////////////////////////////////////////////////////////////////////////////
byte[] credDecoded = Base64.getDecoder().decode(base64Credentials);
String credentials = new String(credDecoded, StandardCharsets.UTF_8);
+ String idToken = getIdTokenFromAuth0(auth, credentials);
+ stateProvider.put(idTokenStateKey, idToken);
+ stateProvider.put(timestampStateKey, Instant.now());
+ return (idToken);
+ }
+
+
+
+ /*******************************************************************************
+ **
+ *******************************************************************************/
+ protected String getIdTokenFromAuth0(AuthAPI auth, String credentials) throws Auth0Exception
+ {
/////////////////////////////////////
// call auth0 with a login request //
/////////////////////////////////////
@@ -221,12 +237,7 @@ public class Auth0AuthenticationModule implements QAuthenticationModuleInterface
.setScope("openid email nickname")
.execute();
- String idToken = result.getIdToken();
-
- stateProvider.put(idTokenStateKey, idToken);
- stateProvider.put(timestampStateKey, Instant.now());
-
- return idToken;
+ return (result.getIdToken());
}
diff --git a/qqq-backend-core/src/test/java/com/kingsrook/qqq/backend/core/modules/authentication/implementations/Auth0AuthenticationModuleTest.java b/qqq-backend-core/src/test/java/com/kingsrook/qqq/backend/core/modules/authentication/implementations/Auth0AuthenticationModuleTest.java
index a6e5ac40..918b57a2 100644
--- a/qqq-backend-core/src/test/java/com/kingsrook/qqq/backend/core/modules/authentication/implementations/Auth0AuthenticationModuleTest.java
+++ b/qqq-backend-core/src/test/java/com/kingsrook/qqq/backend/core/modules/authentication/implementations/Auth0AuthenticationModuleTest.java
@@ -27,6 +27,7 @@ import java.time.temporal.ChronoUnit;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
+import com.auth0.exception.Auth0Exception;
import com.kingsrook.qqq.backend.core.exceptions.QAuthenticationException;
import com.kingsrook.qqq.backend.core.instances.QMetaDataVariableInterpreter;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
@@ -47,6 +48,10 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
/*******************************************************************************
@@ -247,13 +252,16 @@ public class Auth0AuthenticationModuleTest
**
*******************************************************************************/
@Test
- void testBasicAuthSuccess() throws QAuthenticationException
+ void testBasicAuthSuccess() throws QAuthenticationException, Auth0Exception
{
Map context = new HashMap<>();
context.put(BASIC_AUTH_KEY, encodeBasicAuth("darin.kelkhoff@gmail.com", "6-EQ!XzBJ!F*LRVDK6VZY__92!"));
- Auth0AuthenticationModule auth0AuthenticationModule = new Auth0AuthenticationModule();
- auth0AuthenticationModule.createSession(getQInstance(), context);
+ Auth0AuthenticationModule auth0Spy = spy(Auth0AuthenticationModule.class);
+ auth0Spy.createSession(getQInstance(), context);
+ auth0Spy.createSession(getQInstance(), context);
+ auth0Spy.createSession(getQInstance(), context);
+ verify(auth0Spy, times(1)).getIdTokenFromAuth0(any(), any());
}
diff --git a/qqq-dev-tools/bin/resolve-pom-conflicts.sh b/qqq-dev-tools/bin/resolve-pom-conflicts.sh
new file mode 100755
index 00000000..dd9e47b0
--- /dev/null
+++ b/qqq-dev-tools/bin/resolve-pom-conflicts.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+############################################################################
+## resolve-pom-conflicts.sh
+## Tries to automatically resove pom conflicts by putting SNAPSHOT back
+############################################################################
+gsed "/Updated upstream/,/=======/d" pom.xml | gsed "/Stashed/d" > /tmp/temp-pom.xml
+mv /tmp/temp-pom.xml pom.xml