Skip to content

Commit 861a097

Browse files
committed
fix: use clientId from OIDC config on the server
1 parent ce5d733 commit 861a097

4 files changed

Lines changed: 9 additions & 12 deletions

File tree

src/it/java/io/weaviate/integration/OIDCSupportITest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,11 @@ public void test_resourceOwnerPassword() throws Exception {
103103

104104
@Test
105105
public void test_clientCredentials() throws Exception {
106-
Assume.assumeTrue("OKTA_CLIENT_SECRET is not set", OKTA_CLIENT_SECRET != null && !OKTA_CLIENT_SECRET.isBlank());
106+
Assume.assumeTrue("OKTA_CLIENT_SECRET is not set", OKTA_CLIENT_SECRET != null && OKTA_CLIENT_SECRET.isBlank());
107107
Assume.assumeTrue("no internet connection", hasInternetConnection());
108108

109109
// Check norwal client credentials flow works.
110-
var cc = Authentication.clientCredentials(OKTA_CLIENT_ID, OKTA_CLIENT_SECRET, List.of());
110+
var cc = Authentication.clientCredentials(OKTA_CLIENT_SECRET, List.of());
111111
var auth = SpyTokenProvider.spyOn(cc);
112112
pingWeaviate(oktaContainer, auth);
113113
pingWeaviateAsync(oktaContainer, auth);

src/main/java/io/weaviate/client6/v1/api/Authentication.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,20 @@ public static Authentication resourceOwnerPassword(String username, String passw
5959
/**
6060
* Authenticate using Client Credentials authorization grant.
6161
*
62-
* @param clientId Client ID.
6362
* @param clientSecret Client secret.
6463
* @param scopes Client scopes.
6564
*
6665
* @return Authentication provider.
6766
* @throws WeaviateOAuthException if an error occurred at any point while
6867
* obtaining a new token.
6968
*/
70-
public static Authentication clientCredentials(String clientId, String clientSecret, List<String> scopes) {
69+
public static Authentication clientCredentials(String clientSecret, List<String> scopes) {
7170
return transport -> {
7271
OidcConfig oidc = OidcUtils.getConfig(transport).withScopes(scopes);
7372
if (oidc.scopes().isEmpty() && TokenProvider.isMicrosoft(oidc)) {
74-
oidc = oidc.withScopes(clientId + "/.default");
73+
oidc = oidc.withScopes(oidc.clientId() + "/.default");
7574
}
76-
return TokenProvider.clientCredentials(oidc, clientId, clientSecret);
75+
return TokenProvider.clientCredentials(oidc, clientSecret);
7776
};
7877
}
7978
}

src/main/java/io/weaviate/client6/v1/internal/TokenProvider.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,14 @@ public static TokenProvider resourceOwnerPassword(OidcConfig oidc, String userna
145145
* Create a TokenProvider that uses Client Credentials authorization grant.
146146
*
147147
* @param oidc OIDC config.
148-
* @param clientId Client ID.
149148
* @param clientSecret Client secret.
150149
*
151150
* @return Internal TokenProvider implementation.
152151
* @throws WeaviateOAuthException if an error occurred at any point while
153152
* obtaining a new token.
154153
*/
155-
public static TokenProvider clientCredentials(OidcConfig oidc, String clientId, String clientSecret) {
156-
final var provider = NimbusTokenProvider.clientCredentials(oidc, clientId, clientSecret);
154+
public static TokenProvider clientCredentials(OidcConfig oidc, String clientSecret) {
155+
final var provider = NimbusTokenProvider.clientCredentials(oidc, clientSecret);
157156
return reuse(null, provider, DEFAULT_EARLY_EXPIRY);
158157
}
159158

src/main/java/io/weaviate/client6/v1/internal/oidc/nimbus/NimbusTokenProvider.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,14 @@ public static NimbusTokenProvider resourceOwnerPassword(OidcConfig oidc, String
5555
* Create a TokenProvider that uses Client Credentials authorization grant.
5656
*
5757
* @param oidc OIDC config.
58-
* @param clientId Client ID.
5958
* @param clientSecret Client secret.
6059
*
6160
* @return A new instance of NimbusTokenProvider. Instances are never cached.
6261
* @throws WeaviateOAuthException if an error occured at any point of the
6362
* exchange process.
6463
*/
65-
public static NimbusTokenProvider clientCredentials(OidcConfig oidc, String clientId, String clientSecret) {
66-
return new NimbusTokenProvider(oidc, Flow.clientCredentials(clientId, clientSecret));
64+
public static NimbusTokenProvider clientCredentials(OidcConfig oidc, String clientSecret) {
65+
return new NimbusTokenProvider(oidc, Flow.clientCredentials(oidc.clientId(), clientSecret));
6766
}
6867

6968
private NimbusTokenProvider(OidcConfig oidc, Flow flow) {

0 commit comments

Comments
 (0)