8000 making token fetch thread safe · twilio/twilio-java@c046ba6 · GitHub
[go: up one dir, main page]

Skip to content

Commit c046ba6

Browse files
committed
making token fetch thread safe
1 parent a4ab362 commit c046ba6

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/main/java/com/twilio/TwilioOrgsTokenAuth.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class TwilioOrgsTokenAuth {
2020
private static String region = System.getenv("TWILIO_REGION");
2121
private static String edge = System.getenv("TWILIO_EDGE");
2222
private static volatile BearerTokenTwilioRestClient restClient;
23-
@Setter
23+
@Getter @Setter
2424
private static TokenManager tokenManager;
2525

2626
private static volatile ExecutorService executorService;
@@ -87,7 +87,7 @@ private static BearerTokenTwilioRestClient buildOAuthRestClient() {
8787
builder.region(TwilioOrgsTokenAuth.region);
8888
builder.edge(TwilioOrgsTokenAuth.edge);
8989
if(TwilioOrgsTokenAuth.tokenManager == null){
90-
tokenManager = new OrgsTokenManager(grantType, clientId, clientSecret, code, redirectUri, audience, refreshToken, scope);
90+
throw new AuthenticationException("Either initialize the authentications class or pass a custom token manager");
9191
}
9292
builder.tokenManager(TwilioOrgsTokenAuth.tokenManager);
9393

src/main/java/com/twilio/http/bearertoken/BearerTokenTwilioRestClient.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ public BearerTokenTwilioRestClient build() {
109109
public Response request(BearerTokenRequest request) {
110110

111111
if (accessToken == null || accessToken.isEmpty() || isTokenExpired(this.accessToken)) {
112-
this.accessToken = tokenManager.fetchAccessToken();
112+
synchronized (BearerTokenTwilioRestClient.class){
113+
this.accessToken = tokenManager.fetchAccessToken();
114+
}
113115
}
114116

115117
request.setAuth(accessToken);

0 commit comments

Comments
 (0)
0