Skip to content

Commit 09925f7

Browse files
committed
support configurable authMethod
1 parent a08f32f commit 09925f7

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

java/src/main/java/io/kafkaesque/pulsar/client/auth/AuthFactory.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public final class AuthFactory {
99
private AuthFactory() {}
1010

1111
/**
12-
* Request JWT from autho and pass the JWT to pulsar broker.
12+
* Request JWT from auth0 and pass the JWT to pulsar broker.
1313
* @param domain
1414
* @param clientId
1515
* @param clientSecret
@@ -20,4 +20,22 @@ public static Authentication auth0(String domain, String clientId, String client
2020
return new AuthenticationAuth0(Auth0JWT.create(domain, clientId, clientSecret, audience).generateAndCheck());
2121

2222
}
23+
24+
/**
25+
* Request JWT from auth0 with optional authMethod.
26+
* @param domain
27+
* @param clientId
28+
* @param clientSecret
29+
* @param audience
30+
* @param authMethod
31+
* @return
32+
*/
33+
public static Authentication auth0(String domain, String clientId, String clientSecret, String audience, String authMethod) {
34+
String token = Auth0JWT.create(domain, clientId, clientSecret, audience).generateAndCheck();
35+
36+
AuthenticationAuth0 auth0 = new AuthenticationAuth0(token);
37+
auth0.setAuthMethodName(authMethod);
38+
return auth0;
39+
}
40+
2341
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package io.kafkaesque.pulsar.client.auth;
2+
3+
import java.util.Arrays;
4+
import java.util.List;
5+
6+
public final class AuthMethod {
7+
8+
public final static String TOKEN = "token";
9+
10+
public final static String AUTH0 = "auth0";
11+
12+
public final static List<String> supportedMethods = Arrays.asList(TOKEN, AUTH0);
13+
}

java/src/main/java/io/kafkaesque/pulsar/client/auth/AuthenticationAuth0.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public class AuthenticationAuth0 implements Authentication, EncodedAuthenticatio
2525
private static final long serialVersionUID = 1L;
2626
private Supplier<String> tokenSupplier;
2727

28+
private String authMethod = AuthMethod.AUTH0;
29+
2830
public AuthenticationAuth0(String token) {
2931
this(() -> token);
3032
}
@@ -40,7 +42,15 @@ public void close() throws IOException {
4042

4143
@Override
4244
public String getAuthMethodName() {
43-
return "auth0";
45+
return authMethod;
46+
}
47+
48+
public void setAuthMethodName(String name) {
49+
if (AuthMethod.supportedMethods.contains(name)) {
50+
authMethod = name;
51+
} else {
52+
throw new IllegalArgumentException("unsupport auth method " + name);
53+
}
4454
}
4555

4656
@Override

0 commit comments

Comments
 (0)