25
25
import java .util .Arrays ;
26
26
import java .util .Collections ;
27
27
import java .util .HashMap ;
28
- import java .util .List ;
29
28
import java .util .Map ;
30
29
import java .util .Objects ;
31
30
@@ -188,8 +187,7 @@ public final class MongoCredential {
188
187
* The provider name. The value must be a string.
189
188
* <p>
190
189
* If this is provided,
191
- * {@link MongoCredential#REQUEST_TOKEN_CALLBACK_KEY} and
192
- * {@link MongoCredential#REFRESH_TOKEN_CALLBACK_KEY}
190
+ * {@link MongoCredential#OIDC_CALLBACK_KEY}
193
191
* must not be provided.
194
192
*
195
193
* @see #createOidcCredential(String)
@@ -208,45 +206,7 @@ public final class MongoCredential {
208
206
* @see #createOidcCredential(String)
209
207
* @since 4.10
210
208
*/
211
- public static final String REQUEST_TOKEN_CALLBACK_KEY = "REQUEST_TOKEN_CALLBACK" ;
212
-
213
- /**
214
- * Mechanism key for invoked when the OIDC-based authenticator refreshes
215
- * tokens from the identity provider. If this callback is not provided,
216
- * then refresh operations will not be attempted.The type of the value
217
- * must be {@link OidcRefreshCallback}.
218
- * <p>
219
- * If this is provided, {@link MongoCredential#PROVIDER_NAME_KEY}
220
- * must not be provided.
221
- *
222
- * @see #createOidcCredential(String)
223
- * @since 4.10
224
- */
225
- public static final String REFRESH_TOKEN_CALLBACK_KEY = "REFRESH_TOKEN_CALLBACK" ;
226
-
227
- /**
228
- * Mechanism key for a list of allowed hostnames or ip-addresses for MongoDB connections. Ports must be excluded.
229
- * The hostnames may include a leading "*." wildcard, which allows for matching (potentially nested) subdomains.
230
- * When MONGODB-OIDC authentication is attempted against a hostname that does not match any of list of allowed hosts
231
- * the driver will raise an error. The type of the value must be {@code List<String>}.
232
- *
233
- * @see MongoCredential#DEFAULT_ALLOWED_HOSTS
234
- * @see #createOidcCredential(String)
235
- * @since 4.10
236
- */
237
- public static final String ALLOWED_HOSTS_KEY = "ALLOWED_HOSTS" ;
238
-
239
- /**
240
- * The list of allowed hosts that will be used if no
241
- * {@link MongoCredential#ALLOWED_HOSTS_KEY} value is supplied.
242
- * The default allowed hosts are:
243
- * {@code "*.mongodb.net", "*.mongodb-dev.net", "*.mongodbgov.net", "localhost", "127.0.0.1", "::1"}
244
- *
245
- * @see #createOidcCredential(String)
246
- * @since 4.10
247
- */
248
- public static final List <String > DEFAULT_ALLOWED_HOSTS = Collections .unmodifiableList (Arrays .asList (
249
- "*.mongodb.net" , "*.mongodb-dev.net" , "*.mongodbgov.net" , "localhost" , "127.0.0.1" , "::1" ));
209
+ public static final String OIDC_CALLBACK_KEY = "OIDC_CALLBACK" ;
250
210
251
211
/**
252
212
* Creates a MongoCredential instance with an unspecified mechanism. The client will negotiate the best mechanism based on the
@@ -404,9 +364,7 @@ public static MongoCredential createAwsCredential(@Nullable final String userNam
404
364
* @since 4.10
405
365
* @see #withMechanismProperty(String, Object)
406
366
* @see #PROVIDER_NAME_KEY
407
- * @see #REQUEST_TOKEN_CALLBACK_KEY
408
- * @see #REFRESH_TOKEN_CALLBACK_KEY
409
- * @see #ALLOWED_HOSTS_KEY
367
+ * @see #OIDC_CALLBACK_KEY
410
368
* @mongodb.server.release 7.0
411
369
*/
412
370
public static MongoCredential createOidcCredential (@ Nullable final String userName ) {
@@ -639,26 +597,16 @@ public String toString() {
639
597
*/
640
598
@ Evolving
641
599
public interface OidcRequestContext {
642
- /**
643
- * @return The OIDC Identity Provider's configuration that can be used to acquire an Access Token.
644
- */
645
- IdpInfo getIdpInfo ();
646
600
647
601
/**
648
602
* @return The timeout that this callback must complete within.
649
603
*/
650
604
Duration getTimeout ();
651
- }
652
605
653
- /**
654
- * The context for the {@link OidcRefreshCallback#onRefresh(OidcRefreshContext) OIDC refresh callback}.
655
- */
656
- @ Evolving
657
- public interface OidcRefreshContext extends OidcRequestContext {
658
606
/**
659
- * @return The OIDC Refresh token supplied by a prior callback invocation .
607
+ * @return The OIDC callback API version. Currently, version 1 .
660
608
*/
661
- String getRefreshToken ();
609
+ int getVersion ();
662
610
}
663
611
664
612
/**
@@ -673,72 +621,22 @@ public interface OidcRequestCallback {
673
621
* @param context The context.
674
622
* @return The response produced by an OIDC Identity Provider
675
623
*/
676
- IdpResponse onRequest (OidcRequestContext context );
677
- }
678
-
679
- /**
680
- * This callback is invoked when the OIDC-based authenticator refreshes
681
- * tokens from the identity provider. If this callback is not provided,
682
- * then refresh operations will not be attempted.
683
- * <p>
684
- * It does not have to be thread-safe, unless it is provided to multiple
685
- * MongoClients.
686
- */
687
- public interface OidcRefreshCallback {
688
- /**
689
- * @param context The context.
690
- * @return The response produced by an OIDC Identity Provider
691
- */
692
- IdpResponse onRefresh (OidcRefreshContext context );
693
- }
694
-
695
- /**
696
- * The OIDC Identity Provider's configuration that can be used to acquire an Access Token.
697
- */
698
- @ Evolving
699
- public interface IdpInfo {
700
- /**
701
- * @return URL which describes the Authorization Server. This identifier is the
702
- * iss of provided access tokens, and is viable for RFC8414 metadata
703
- * discovery and RFC9207 identification.
704
- */
705
- String getIssuer ();
706
-
707
- /**
708
- * @return Unique client ID for this OIDC client.
709
- */
710
- String getClientId ();
711
-
712
- /**
713
- * @return Additional scopes to request from Identity Provider. Immutable.
714
- */
715
- List <String > getRequestScopes ();
624
+ RequestCallbackResult onRequest (OidcRequestContext context );
716
625
}
717
626
718
627
/**
719
628
* The response produced by an OIDC Identity Provider.
720
629
*/
721
- public static final class IdpResponse {
630
+ public static final class RequestCallbackResult {
722
631
723
632
private final String accessToken ;
724
633
725
- @ Nullable
726
- private final Integer accessTokenExpiresInSeconds ;
727
-
728
- @ Nullable
729
- private final String refreshToken ;
730
-
731
634
/**
732
635
* @param accessToken The OIDC access token
733
- * @param accessTokenExpiresInSeconds The expiration in seconds. If null, the access token is single-use.
734
- * @param refreshToken The refresh token. If null, refresh will not be attempted.
735
636
*/
736
- public IdpResponse (final String accessToken , @ Nullable final Integer accessTokenExpiresInSeconds ,
737
- @ Nullable final String refreshToken ) {
637
+ public RequestCallbackResult (final String accessToken ) {
738
638
notNull ("accessToken" , accessToken );
739
639
this .accessToken = accessToken ;
740
- this .accessTokenExpiresInSeconds = accessTokenExpiresInSeconds ;
741
- this .refreshToken = refreshToken ;
742
640
}
743
641
744
642
/**
@@ -747,22 +645,5 @@ public IdpResponse(final String accessToken, @Nullable final Integer accessToken
747
645
public String getAccessToken () {
748
646
return accessToken ;
749
647
}
750
-
751
- /**
752
- * @return The expiration time for the access token in seconds.
753
- * If null, the access token is single-use.
754
- */
755
- @ Nullable
756
- public Integer getAccessTokenExpiresInSeconds () {
757
- return accessTokenExpiresInSeconds ;
758
- }
759
-
760
- /**
761
- * @return The OIDC refresh token. If null, refresh will not be attempted.
762
- */
763
- @ Nullable
764
- public String getRefreshToken () {
765
- return refreshToken ;
766
- }
767
648
}
768
649
}
0 commit comments