@@ -85,7 +85,8 @@ public final class OidcAuthenticator extends SaslAuthenticator {
8585 private static final List <String > ALLOWS_USERNAME = Arrays .asList (
8686 AZURE_ENVIRONMENT );
8787
88- private static final Duration CALLBACK_TIMEOUT = Duration .ofMinutes (5 );
88+ private static final Duration CALLBACK_TIMEOUT = Duration .ofMinutes (1 );
89+ private static final Duration HUMAN_CALLBACK_TIMEOUT = Duration .ofMinutes (5 );
8990
9091 public static final String OIDC_TOKEN_FILE = "OIDC_TOKEN_FILE" ;
9192
@@ -112,6 +113,10 @@ public OidcAuthenticator(final MongoCredentialWithCache credential,
112113 }
113114 }
114115
116+ private Duration getCallbackTimeout () {
117+ return isHumanCallback () ? HUMAN_CALLBACK_TIMEOUT : CALLBACK_TIMEOUT ;
118+ }
119+
115120 @ Override
116121 public String getMechanismName () {
117122 return MONGODB_OIDC .getMechanismName ();
@@ -306,7 +311,7 @@ private byte[] evaluate(final byte[] challenge) {
306311 // Invoke Callback using cached Refresh Token
307312 fallbackState = FallbackState .PHASE_2_REFRESH_CALLBACK_TOKEN ;
308313 OidcCallbackResult result = requestCallback .onRequest (new OidcCallbackContextImpl (
309- CALLBACK_TIMEOUT , cachedIdpInfo , cachedRefreshToken , userName ));
314+ getCallbackTimeout () , cachedIdpInfo , cachedRefreshToken , userName ));
310315 jwt [0 ] = populateCacheWithCallbackResultAndPrepareJwt (cachedIdpInfo , result );
311316 } else {
312317 // cache is empty
@@ -315,7 +320,7 @@ private byte[] evaluate(final byte[] challenge) {
315320 // no principal request
316321 fallbackState = FallbackState .PHASE_3B_CALLBACK_TOKEN ;
317322 OidcCallbackResult result = requestCallback .onRequest (new OidcCallbackContextImpl (
318- CALLBACK_TIMEOUT , userName ));
323+ getCallbackTimeout () , userName ));
319324 jwt [0 ] = populateCacheWithCallbackResultAndPrepareJwt (null , result );
320325 if (result .getRefreshToken () != null ) {
321326 throw new MongoConfigurationException (
@@ -345,7 +350,7 @@ private byte[] evaluate(final byte[] challenge) {
345350 // there is no cached refresh token
346351 fallbackState = FallbackState .PHASE_3B_CALLBACK_TOKEN ;
347352 OidcCallbackResult result = requestCallback .onRequest (new OidcCallbackContextImpl (
348- CALLBACK_TIMEOUT , idpInfo , null , userName ));
353+ getCallbackTimeout () , idpInfo , null , userName ));
349354 jwt [0 ] = populateCacheWithCallbackResultAndPrepareJwt (idpInfo , result );
350355 }
351356 }
@@ -606,6 +611,11 @@ public static void validateBeforeUse(final MongoCredential credential) {
606611 Object environmentName = credential .getMechanismProperty (ENVIRONMENT_KEY , null );
607612 Object machineCallback = credential .getMechanismProperty (OIDC_CALLBACK_KEY , null );
608613 Object humanCallback = credential .getMechanismProperty (OIDC_HUMAN_CALLBACK_KEY , null );
614+ boolean allowedHostsIsSet = credential .getMechanismProperty (ALLOWED_HOSTS_KEY , null ) != null ;
615+ if (humanCallback == null && allowedHostsIsSet ) {
616+ throw new IllegalArgumentException (ALLOWED_HOSTS_KEY + " must be specified only when "
617+ + OIDC_HUMAN_CALLBACK_KEY + " is specified" );
618+ }
609619 if (environmentName == null ) {
610620 // callback
611621 if (machineCallback == null && humanCallback == null ) {
0 commit comments