Skip to content

Commit d460444

Browse files
katcharovstIncMale
andauthored
Remove non-machine workflow (#1259)
* Remove non-machine workflow * Update prose tests to remove refresh token, principal-request * Conform to latest spec; remove lock around server auth * Rebase fix (async API) * Apply suggestions from code review Co-authored-by: Valentin Kovalenko <valentin.kovalenko@mongodb.com> * PR fixes --------- Co-authored-by: Valentin Kovalenko <valentin.kovalenko@mongodb.com>
1 parent ec9887b commit d460444

File tree

14 files changed

+706
-1570
lines changed

14 files changed

+706
-1570
lines changed

Diff for: driver-core/src/main/com/mongodb/MongoCredential.java

+8-127
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.util.Arrays;
2626
import java.util.Collections;
2727
import java.util.HashMap;
28-
import java.util.List;
2928
import java.util.Map;
3029
import java.util.Objects;
3130

@@ -188,8 +187,7 @@ public final class MongoCredential {
188187
* The provider name. The value must be a string.
189188
* <p>
190189
* 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}
193191
* must not be provided.
194192
*
195193
* @see #createOidcCredential(String)
@@ -208,45 +206,7 @@ public final class MongoCredential {
208206
* @see #createOidcCredential(String)
209207
* @since 4.10
210208
*/
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";
250210

251211
/**
252212
* 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
404364
* @since 4.10
405365
* @see #withMechanismProperty(String, Object)
406366
* @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
410368
* @mongodb.server.release 7.0
411369
*/
412370
public static MongoCredential createOidcCredential(@Nullable final String userName) {
@@ -639,26 +597,16 @@ public String toString() {
639597
*/
640598
@Evolving
641599
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();
646600

647601
/**
648602
* @return The timeout that this callback must complete within.
649603
*/
650604
Duration getTimeout();
651-
}
652605

653-
/**
654-
* The context for the {@link OidcRefreshCallback#onRefresh(OidcRefreshContext) OIDC refresh callback}.
655-
*/
656-
@Evolving
657-
public interface OidcRefreshContext extends OidcRequestContext {
658606
/**
659-
* @return The OIDC Refresh token supplied by a prior callback invocation.
607+
* @return The OIDC callback API version. Currently, version 1.
660608
*/
661-
String getRefreshToken();
609+
int getVersion();
662610
}
663611

664612
/**
@@ -673,72 +621,22 @@ public interface OidcRequestCallback {
673621
* @param context The context.
674622
* @return The response produced by an OIDC Identity Provider
675623
*/
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);
716625
}
717626

718627
/**
719628
* The response produced by an OIDC Identity Provider.
720629
*/
721-
public static final class IdpResponse {
630+
public static final class RequestCallbackResult {
722631

723632
private final String accessToken;
724633

725-
@Nullable
726-
private final Integer accessTokenExpiresInSeconds;
727-
728-
@Nullable
729-
private final String refreshToken;
730-
731634
/**
732635
* @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.
735636
*/
736-
public IdpResponse(final String accessToken, @Nullable final Integer accessTokenExpiresInSeconds,
737-
@Nullable final String refreshToken) {
637+
public RequestCallbackResult(final String accessToken) {
738638
notNull("accessToken", accessToken);
739639
this.accessToken = accessToken;
740-
this.accessTokenExpiresInSeconds = accessTokenExpiresInSeconds;
741-
this.refreshToken = refreshToken;
742640
}
743641

744642
/**
@@ -747,22 +645,5 @@ public IdpResponse(final String accessToken, @Nullable final Integer accessToken
747645
public String getAccessToken() {
748646
return accessToken;
749647
}
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-
}
767648
}
768649
}

Diff for: driver-core/src/main/com/mongodb/internal/connection/InternalStreamConnection.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ public <T> void sendAndReceiveAsync(final CommandMessage message, final Decoder<
383383
message, decoder, sessionContext, requestContext, operationContext, c);
384384
beginAsync().<T>thenSupply(c -> {
385385
sendAndReceiveAsyncInternal.getAsync(c);
386-
}).onErrorIf(e -> reauthenticationIsTriggered(e), c -> {
386+
}).onErrorIf(e -> reauthenticationIsTriggered(e), (t, c) -> {
387387
reauthenticateAndRetryAsync(sendAndReceiveAsyncInternal, c);
388388
}).finish(callback);
389389
}

0 commit comments

Comments
 (0)