Skip to content

Commit

Permalink
chore: updated fetching token in getAuthString method
Browse files Browse the repository at this point in the history
  • Loading branch information
sbansla committed Oct 3, 2024
1 parent 58a022a commit 0f10880
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,15 @@ public class Example {
}
```

### OAuth Feature For Organisation APIss
We are introducing Client Credentials Flow-based OAuth 2.0 authentication.
This feature is currently in `beta` and its implementation is subject to change.

Detailed example [here](https://github.com/twilio/twilio-java/tree/main/examples/BearerTokenAuthentication.md)

### OAuth Feature
We are introducing Client Credentials Flow-based OAuth 2.0 authentication.
This feature is currently in beta and its implementation is subject to change.
This feature is currently in `beta` and its implementation is subject to change.

Detailed examples [here](https://github.com/twilio/twilio-java/tree/main/examples/FetchMessageUsingOAuth.md)

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/twilio/auth_strategy/TokenAuthStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public TokenAuthStrategy(TokenManager tokenManager) {

@Override
public String getAuthString() {
fetchToken();
return "Bearer " + token;
}

Expand All @@ -34,6 +35,7 @@ public void fetchToken() {
synchronized (TokenAuthStrategy.class){
if (this.token == null || this.token.isEmpty() || isTokenExpired(this.token)) {
logger.info("Fetching new token for Apis");
System.out.println("Fetching new token for Apis");
this.token = tokenManager.fetchAccessToken();
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/com/twilio/http/TwilioRestClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,8 @@ protected TwilioRestClient(Builder b) {
public Response request(final Request request) {
if (username != null && password != null) {
request.setAuth(username, password);
} else if (authStrategy != null) { // TODO: Test this code
} else if (authStrategy != null) {
request.setAuth(authStrategy);
if (EnumConstants.AuthType.TOKEN.equals(authStrategy.getAuthType())) {
((TokenAuthStrategy)authStrategy).fetchToken();
}
}

if (region != null)
Expand Down

0 comments on commit 0f10880

Please sign in to comment.